1

I'm learning React following an Udemy course. Instructor said that useEffect with empty depends array should runs only once (on mount), but I'm seeing two logs in my console with this simple code:

import { useEffect } from "react";

export default function App() {
  useEffect(() => {
    console.log("Should run one time");
  }, []);
  return <div>Hello World</div>;
}

Is there something I missed here?

Youssouf Oumar
  • 29,373
  • 11
  • 46
  • 65
  • Does this answer your question? [React Hooks: useEffect() is called twice even if an empty array is used as an argument](https://stackoverflow.com/questions/60618844/react-hooks-useeffect-is-called-twice-even-if-an-empty-array-is-used-as-an-ar) – Mod3rnx Sep 23 '22 at 15:05
  • 1
    Thanks @yousoumar, turns out the course I'm following is recored in 2020, so instructor did not mention StrictMode. –  Sep 23 '22 at 15:12

0 Answers0