I am trying to map a json response into a state, what I am trying to do is map all the children of this array no matter how many, as in skipping the first array and only show its children, here is what i tried to do
fetch(api).then((response) => {
response.json() .then((data) => {
data.children.map( (menu) => {
this.setState({
mydata: menu
})
}) console.log("test", this.state.mydata )})
});
this is what i receive from the api
{
"name": "Store 1",
"children": [
{
"name": "Store 1",
"children": [{},{}...]
},
{
"name": "Store 2",
"children": [{},{}...]
}
]
}
and this is how i want it stored in my state,
[
{
"name": "Store 1",
"children": [{},{}...]
},
{
"name": "Store 2",
"children": [{},{}...]
}
]
this.setState()in loop over the samekeyis the issue..