Hey guys!
So I have started creating an amazon clone and I am having a bit of a problem with amazon side menu (the on that shows when you click on the burger icon).
At the moment I did that much:
- It’s a functional component.
- Menu shows on the click of the button (have separate close button as well)
- You can navigate through it - It has 4 working buttons of “Categories” type. Those buttons are created from an array of objects :
const categories = [
{
"name": "Electronics",
"subCat": ["Desktop PC","Consoles","TV"]
}
]
There is 3 more objects, don’t want to spam all of it here They are constructed exactly the same. So the 4 buttons I have mentioned earlier are created within return statement:
<div className="navbar-secondary-part1" >
<ButtonGroup
color="primary"
orientation="vertical"
fullWidth={ true }
variant="text">
{categories.map(category => {
return(
<Button
onClick={ navigate }
key={ uuid() }
value={ category.name }>
{ category.name }
</Button>
)
})}
</ButtonGroup>
<div>
This is part 1 out of 2 in the menu. Next sibling is “navbar-secondary-part2” and my goal is to render sub-category buttons (subCat in the categories array - in this case desktop pc, consoles and tv) in part2 after user chooses the category he wants to browse. How can I do it?
I tried using state from useState hook, but it won’t work as it needs to wait for user to choose category, so it just shows error.
Also I know I could use react router, but that means I would need to rework a lot of it, unless that’s the best option?
Thanks in advance for any advice
Pawel