Question presented to candidate:
"Your app is wrapped in <StrictMode> and someone notices every effect appears to run twice in development. Is that a bug? What is StrictMode actually for?"
What a strong answer should cover:
- It is a development-only tool. It renders no UI and is completely inert in production builds.
- It intentionally double-invokes component render functions, and mounts-unmounts-remounts to run each effect twice.
- The purpose: surface bugs that would otherwise appear only later — impure renders and missing effect cleanup.
- Double-invoking render exposes side effects hiding in the render phase, since a pure function run twice is harmless.
- The mount-unmount-remount cycle exposes effects that do not clean up after themselves.
- It also warns about deprecated and legacy APIs.
- Crucially: it does not change production behaviour, so "fixing" it by removing StrictMode hides a real bug rather than solving it.
- Forward-looking: the remount simulation prepares components for features that preserve and restore state.
Clarifying questions expected:
- "Is the double-run happening in production too?" (It should not be — that would point elsewhere.)
- "Which React version?" — the effect double-invoke behaviour arrived in React 18.
Code / implementation expected: Optional. A subscription effect with correct cleanup is the natural demonstration.