Repaso
Español
Frontend & WebIntermediateFE-10

useEffect(fn, []) runs fn…

Options

  1. After every render of the same component
  2. Once after mount, and cleans up on unmount (Correct option)
  3. Before the first render of the component
  4. Never, since an empty array disables effects

Answer

Once after the component mounts (cleanup on unmount); in development StrictMode it mounts, unmounts and re-runs once to surface bugs

Why

useEffect runs side effects (fetching data, subscriptions, timers) after React has drawn the component.

The dependency array says when to re-run it: [] = only after the first render; [userId] = whenever userId changes; no array = after every render.

The function you return is the cleanup (unsubscribe, clear timers). In development, StrictMode runs effects twice on purpose to reveal missing cleanups.

Remember

Dependency array controls when an effect re-runs.

Key terms

Practice this question in Repaso