Skip to main content
StrictMode is a development tool for highlighting potential problems in an application. It activates additional checks and warnings for its descendants.
StrictMode is development-only and has no effect in production builds. It doesn’t render any visible UI and doesn’t impact the user experience.

Usage

Type

Internally, StrictMode is represented by the symbol Symbol.for('react.strict_mode') (the value of REACT_STRICT_MODE_TYPE in React’s source).

What StrictMode Checks

StrictMode enables several development-only behaviors to help identify issues:

1. Identifying Unsafe Lifecycles

StrictMode warns about legacy lifecycle methods that are unsafe for async rendering:
  • componentWillMount → Use componentDidMount or constructor
  • componentWillReceiveProps → Use getDerivedStateFromProps or componentDidUpdate
  • componentWillUpdate → Use getSnapshotBeforeUpdate or componentDidUpdate

2. Warning About Legacy String Refs

String refs are deprecated and will warn in StrictMode:

3. Detecting Unexpected Side Effects

StrictMode double-invokes certain functions in development to help detect side effects: Functions that are double-invoked:
  • Function component bodies
  • useState, useMemo, and useReducer initializer functions
  • Class component constructor, render, and shouldComponentUpdate methods
  • getDerivedStateFromProps static method
Why double-invoke? This helps catch bugs caused by impure functions. Pure functions should produce the same result when called multiple times, so calling them twice shouldn’t cause issues. If your code breaks with double-invocation, it indicates a side effect that could cause bugs.

4. Detecting Legacy Context API

StrictMode warns about usage of the legacy context API:

5. Detecting Deprecated findDOMNode Usage

findDOMNode is deprecated and will warn in StrictMode:

6. Ensuring Reusable State (React 18+)

In React 18+, StrictMode simulates mounting, unmounting, and remounting components to ensure state can be preserved:
This helps ensure your cleanup functions work correctly and your components can handle being mounted multiple times.

Enabling StrictMode

For Your Entire App

Wrap your entire app in StrictMode:

For Part of Your App

You can enable StrictMode for specific component trees:

Nested StrictMode

StrictMode can be nested, and inner StrictMode has no additional effect:

Common Issues and Fixes

Issue: My component is rendering twice!

This is intentional. StrictMode double-invokes render functions in development to help catch bugs. This only happens in development mode.
What to do: Ensure your render function is pure (no side effects). If you see issues, you’ve found a bug that StrictMode helped expose.

Issue: My useEffect is running twice on mount!

This is intentional in React 18+. StrictMode simulates mounting, unmounting, and remounting:
What to do: Ensure your effect cleanup functions work correctly. This prepares your code for features like Fast Refresh and component reuse.

Issue: setState in constructor/render is causing issues

Issue: External API is being called twice

StrictMode in Tests

You can wrap your test components in StrictMode to get the same checks during testing:

Migration Strategy

If you’re adding StrictMode to an existing app:
  1. Start small: Wrap individual components or features first
  2. Fix warnings: Address StrictMode warnings as they appear
  3. Expand gradually: Move StrictMode up the tree as you fix issues
  4. Eventually wrap the whole app: Once all warnings are resolved

Benefits

Using StrictMode helps you:
  • Catch bugs early: Find issues in development before users see them
  • Write better code: Encourages best practices and pure functions
  • Future-proof your app: Prepares your code for future React features
  • Easier refactoring: Helps identify code that will break with updates
  • Better performance: Helps identify unnecessary re-renders and side effects
Don’t remove StrictMode just because it causes your component to render twice! This is catching real bugs. Fix the underlying issues instead.

Example: Before and After StrictMode

Before (with bugs):
After (bug revealed and fixed):