V
V
Vladimir2020-05-23 09:00:57
React
Vladimir, 2020-05-23 09:00:57

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} />
    )


Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
abberati, 2020-05-23
@HistoryART

useEffect(() => {
    getMenu();
}, []);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question