Three Use Cases for React’s useEffect Hook
/** * @link: https://www.w3schools.com/react/react_useeffect.asp * * useEffect Examples with: */ // 1. No dependency passed: useEffect(() => { //Runs on every render }); // 2. An empty array: useEffect(() => { //Runs only on the first render }, []); // 3. Array of Props or state values: useEffect(() => { // Runs on the first render // And any time any dependency value changes // video explainer: https://www.youtube.com/watch?v=UVhIMwHDS7k&t=660s }, [prop, state])