Paul Hub
Paul Hub

Reputation: 181

How to make a map on JSON object with children

My menu consists of sub menu, that's why my JSON is composed like this:

"Accueil" -> "Espace documentaire"

"Déploiement" -> "Indicateurs de déploiement", "Fichiers NetGeo", "Fichiers STBAN" ...

So I want to make a menu with a Treeview that initially displays the map "Accueil" then the (children) "Espace documentaire"

Here is the JSON object:

https://pastebin.com/km399QFQ

Here is the function:

getMenuItems().then(response => {
    const item = response.data;
    return(
        <div>
            { console.log(item) }
            { item.map(menu => {
                return (
                   // ...
                );
            })};
        </div>
    );
});

Upvotes: 0

Views: 706

Answers (1)

Ivan Burnaev
Ivan Burnaev

Reputation: 2730

Paul, I've made a simple showcase for you: https://m1go3.csb.app/. There is a recursive function component to render nested children items.

Here is the link to the source: https://codesandbox.io/s/ecstatic-hofstadter-m1go3

Upvotes: 2

Related Questions