Question · JavaScript and React course · Module 5: useEffect and Custom Hooks

useEffect and Lifecycle

What is the main difference between useEffect(() => {}, []) and componentDidMount?

Answer options

  • useEffect runs synchronously, componentDidMount runs asynchronously
  • useEffect can return a cleanup function, componentDidMount cannot
  • No difference, they work identically
  • useEffect runs after painting, componentDidMount runs before

You can check the correct answer by solving this task in the CodeWorlds game.