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

Conditional Effect Execution

How do you correctly implement a conditional effect?

Answer options

  • if (condition) useEffect(() => {})
  • useEffect(() => { if (condition) {...} }, [condition])
  • useEffect(condition ? () => {} : null)
  • useEffect(() => {}, condition ? [] : null)

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