I have two api that I should turn them array like that
[
{
key: "0",
label: 'Installation',
children: [
{ key: "0-0", label: 'Getting Started', url: 'https://reactjs.org/docs/getting-started.html' },
{ key: "0-1", label: 'Add React', url: 'https://reactjs.org/docs/add-react-to-a-website.html' },
{ key: "0-2", label: 'Create an App', url: 'https://reactjs.org/docs/create-a-new-react-app.html' },
{ key: "0-3", label: 'CDN Links', url: 'https://reactjs.org/docs/cdn-links.html' }
]
},
{
key: "1",
label: 'Main Concepts',
children: [
{ key: "1-0", label: 'Hello World', url: 'https://reactjs.org/docs/hello-world.html' },
{ key: "1-1", label: 'Introducing JSX', url: 'https://reactjs.org/docs/introducing-jsx.html' },
{ key: "1-2", label: 'Rendering Elements', url: 'https://reactjs.org/docs/rendering-elements.html' },
{ key: "1-3", label: 'Components and Props', url: 'https://reactjs.org/docs/components-and-props.html' },
{ key: "1-4", label: 'State and LifeCycle', url: 'https://reactjs.org/docs/state-and-lifecycle.html' },
{ key: "1-5", label: 'Handling Events', url: 'https://reactjs.org/docs/handling-events.html' }
]
}
];
By the way, I have two API, one of them get all categories, the second API is to take the names of the children. So I created chained fetch, but I can not take the children object correctly. children array turns that 'children: Promise {: Array(11)}' What does fullfilled mean here? because my code not working due to that reason. I want to share my code also
getCategories() {
return fetch('https://challenge.fnaghshin.com/api/cat')
.then((res) => res.json())
.then((d) => {
return Promise.all(
d.map((e) => {
return {
key: e.id,
label: e.name,
date: e.created_at,
children: fetch(
`https://challenge.fnaghshin.com/api/catpro/${e.id}`
)
.then((res) => res.json())
.then((d) =>
d.map((e) => {
return {
key: e.id,
label: e.name,
};
})
),
};
})
);
});
}
I also used Promise.all() to wait all promises fullfilled than turn me right array.But I failed