import {useEffect} from "react";
Just add an empty array
after the callback function
separated by a comma
useEffect(callback, []);
useEffect(()=>{}, []);
Why do you need to run useEffect() only once?
When you setState inside useEffect() from a data source, it will be continuously updating with the source value, and outside the useEffect() if you have an onChange event handler to setState to another value- that won't work. To solve this, you need to call useEffect() only once.
Top comments (0)