I'm quite new to react and trying to understand how to pass props.
1st i have set a Navlink component which holds a subcategories property :
<NavLink
catid={category.id}
to={category.route}
catname={category.name}
subcategories={category.subcategories}
>
{category.name}
</NavLink>
{category.route}, {category.name}, {category.subcategories} are fetched from json file, so this part is OK.
Each route is defined so:
<Route
path='/epicerie-sucree'
render={(props) => (
<CategoryPage
{...props}
catid={10}
catname={"Epicerie sucrée"}
subcategories={props.subcategories}
/>
)}
/>
so it renders a component named <CategoryPage/>
And here's the code of the CategoryPage Component :
export default function CategoryPage(props) {
return (
<div>
{ props.subcategories.map(subcat => (
<div>{subcat.subcat_name}</div>
))}
<FooterCat cat={catData.categories}></FooterCat>
</div>)
}
So the categoryPage component should receive correctly the props transmitted through the router, no ?
Instead it throws an error "TypeError: Cannot read property 'map' of undefined" I don't understand... Thanks