Shouldn’t that be
{
if (!slice.fields) {
return null;
} else {
return slice.fields.map((secondaryNav, index) => {
<!-- markup is rendered here -->
})
}
}
I have also followed the tutorial and to make rendering the markup easier I preprocess the result of the navigation to create a nested structure
const items = content.body.reduce((acc, el) => {
if (acc.length === 0) {
return [el];
}
const current = acc.pop();
if (current.slice_type === el.slice_type) {
acc.push(current);
acc.push(el);
} else {
acc.push({ ...current, items: [...current.items, el] });
}
return acc;
}, []);
this way I go from a flat list of navigation items which declare a nesting level to a nested list of lists of navigation items
so
[
{level_1, ...item1},
{level_2, ...item1},
{level_2, ...item2},
{level_1, ...item2},
{level_2, ...item1},
{level_2, ...item2},...
]
becomes
{
{
level_1,
items:[
{level_2, ...item1},
{level_2, ...item2},
],
...item1
},
{
level_1,
items:[
{level_2, ...item1},
{level_2, ...item2},
],
...item2
},
...
]