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>;

}
...