I have a nested JSON, by which I am making a UI, I have successfully created the first part, Issue I am facing is for the second part.
What I am trying to do
I have a nested json by which I am showing parent element, now what I want to do is on click of any parent it should show that particular data.
suppose I click on parent1 so it should show child of parent one.
My JSON data
[
{
"name": "parent1",
"url": "url1",
"child": [
{
"name": "child1",
"url": "child_url1",
"grand_child": [
{
"name": "some name",
"url": "some url"
}
]
},
{
"name": "child2",
"url": "child_url2"
},
{
"name": "child3",
"url": "child_url3"
}
]
},
{
"name": "parent2",
"url": "url2",
"child": [
{
"name": "child22",
"url": "child_url22"
}
]
},
{
"name": "parent3",
"url": "url3",
"child": [
{
"name": "child33",
"url": "child_url33"
},
{
"name": "child44",
"url": "child_url44"
},
{
"name": "child55",
"url": "child_url55"
}
]
}
]
What I am doing
<div className="row">
{d.map((li) => (
<div className="col-12 col-sm-12 col-md-6 col-lg-4 col-xl-4">
<div onClick={() => on_click}>{li.name}</div>
</div>
))}
</div>
But now I don't know how to show other part after onClick how to have that particular data.
What I am trying to acheive is something like this Code sandbox
in my code sandbox I am just showing parent3 children (assuming that is clicked at that time)