Common Mistakes

Pitfalls

  • Missing dependencies: the effect uses a stale value. Add every value it uses to the array (ESLint warns you).
  • Infinite loop: setting state in an effect with no dependency array, or depending on an object created each render.
  • Using effects for calculations: derive values during render instead (const total = items.length).
  • Runs twice in development: StrictMode mounts, unmounts and mounts again to test your cleanup. Production runs once.