-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu-item.jsx
38 lines (33 loc) · 992 Bytes
/
menu-item.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { useState } from "react";
import MenuList from "./menu-list";
export default function MenuItem({ item }) {
const [displayCurrentChildren, setDisplayCurrentChildren] = useState({})
function handleToggleChildren(getCurrentLabel) {
setDisplayCurrentChildren({
...displayCurrentChildren,
[getCurrentLabel] : !displayCurrentChildren[getCurrentLabel]
})
}
console.log(displayCurrentChildren)
return (
<li>
<div className="menu-item">
<p>{item.label}</p>
{
item && item.children && item.children.length
? <span onClick={() => handleToggleChildren(item.label)}>
{
displayCurrentChildren[item.label] ? '-' : "+"
}
</span>
: null
}
</div>
{
item && item.children && item.children.length > 0 && displayCurrentChildren[item.label] ?
<MenuList list={item.children} />
: null
}
</li>
)
}