React Strict Mode: Why Double Rendering Happens
⚛ ری‌اکت

React Strict Mode: Why Double Rendering Happens

Development-only behaviors that expose side effects and prepare you for concurrent React.

BugCast Admin··۵ دقیقه مطالعه

React Strict Mode intentionally double-invokes certain lifecycles and effects in development to surface impure side effects. It does not run twice in production.

Common Interview Questions

Q: What does Strict Mode double-invoke?

Answer: In React 18+ dev, components mount, unmount, and remount; effects run setup-cleanup-setup. Class constructors and certain hooks are stress-tested.

Q: Why does React do this?

Answer: To ensure effects are idempotent and cleanup works — preparing for concurrent features where React may mount/unmount/resume components.

Q: My API fires twice in dev — bug?

Answer: Often expected in dev without proper cleanup or deduplication. Fix effect cleanup; do not disable Strict Mode as the solution.


<React.StrictMode>
  <App />
</React.StrictMode>

Q: Does Strict Mode affect production?

Answer: No double rendering in production builds. Strict Mode checks are development-only warnings and behaviors.

Key Points for Interviews

  • Dev-only behavior — not a production perf hit

  • Exposes missing effect cleanup

  • Helps future-proof for concurrent rendering

  • Wrap app root with <StrictMode> in development

  • Use idempotent effects and proper abort/cleanup

#strict-mode#development#interview

مطالب مرتبط