Answer the question
In order to leave comments, you need to log in
How to get state once without subsequent updates?
Good afternoon. Can you please tell me how can I stop the status check? I have a multi-level menu and when I try to open it - it's not possible to catch items below the 2nd level, what outputs do I have?
let [nav, setNav] = useState([]);
const getMenu = async() => {
let menu = await fetch('http://localhost:4000/menu', {method: 'post'});
menu = await menu.json();
return setNav(menu)
};
const UseMenu = ({element}) => element.map(el => (
<ul className='select'>
<li> {el.title} </li>
<div className="selectContent">
<li onClick={selectItem}>
<ul className='select'>
<li> {el.title} </li>
<div className="selectContent">
{el.children ? (<UseMenu element={el.children} />) : ''}
</div>
</ul>
</li>
</div>
</ul>
));
useEffect(() => {
getMenu();
});
return (
<UseMenu element={nav} />
)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question