0 votes
in React Hooks by
How to call loading function with React useEffect only once?

1 Answer

0 votes
by
If you only want to run the function given to useEffect after the initial render, you can give it an empty array [] as the second argument.

For example:

function MyComponent(){

    useEffect(() => {

        loadDataOnlyOnce();

    }, []);

    return <div> { /*...*/} </div>;

}

Related questions

0 votes
asked May 30, 2023 in React Hooks by Robindeniel
0 votes
+1 vote
asked Mar 2, 2020 in ReactJS by RShastri
...