React Strict Mode Explained: How to Apply It in Your Projects
Updated on Jun 10, 2025 | 27 min read | 10.58K+ views
Share:
For working professionals
For fresh graduates
More
Updated on Jun 10, 2025 | 27 min read | 10.58K+ views
Share:
Table of Contents
Latest Update: React Strict Mode now intentionally invokes certain functions twice, such as component render functions, state initializer functions, and effect functions. This behavior helps in detecting unexpected side effects and ensures that components are resilient to being mounted and unmounted multiple times. |
React Strict Mode is a development tool that helps catch common bugs and side effects by running extra checks that simulate production-like behaviors, such as identifying unsafe lifecycles and preparing your app for upcoming features like concurrent rendering. This proactive approach makes your code more reliable and future-proof, helping you avoid issues before they reach users.
In this blog, you'll learn what React Strict Mode is, how it works, and how to apply it correctly in your projects. We'll explore its main benefits, the common issues it detects, its limitations, and complementary tools to enhance your development workflow.
Looking to improve your React skills and build reliable, scalable applications? Explore upGrad’s Software Engineering course to learn best practices, debugging techniques, and modern development workflows. Start advancing your career with practical, industry-relevant training today!
React Strict Mode is a development-only feature that helps you prepare your app for React's evolving architecture, especially Concurrent Rendering. By wrapping components using <React.StrictMode> in your JavaScript code, you enable additional checks that detect unsafe lifecycle methods, legacy API usage, and side effects that could cause bugs during concurrent execution.
These checks run during development, such as double-invoking functions or effects, to surface hidden issues early. Although Strict Mode has no impact on production builds, it simulates potential problems that may appear with future React features.
In this section, you will learn how React Strict Mode works and how adding it to your code improves reliability and code quality.
If you want to strengthen your React skills and build robust, high-quality web applications, the following courses from upGrad can guide your journey:
React Strict Mode works by running additional checks and warnings on your components during development. It helps you spot issues like deprecated APIs, unexpected side effects, and unsafe lifecycle methods without affecting your app's performance in production.
This section explains the specific mechanisms behind how React Strict Mode operates in your applications and what to expect when you enable it.
Double-Invocation: What It Means and Why It Matters
When using StrictMode in React, specific functions and lifecycle methods are invoked twice in development mode. This includes:
This behavior ensures that components avoid unsafe assumptions that could break under concurrent rendering. It is especially effective at detecting unintended side effects, such as state mutations during rendering, improper subscriptions that aren't cleaned up correctly, and API calls made directly within render methods or outside appropriate lifecycle hooks.
By highlighting these issues early, React Strict Mode helps you write components that behave predictably and remain stable when React's concurrent features are enabled.
React Strict Mode modifies how components behave during development. Here's how it compares to normal rendering in React applications:
Feature or Method |
Normal React Rendering |
React Strict Mode (Development Only) |
Consequences / Why It Matters |
Functional component render | Called once | Called twice to detect unsafe operations | Reveals side effects or mutations happening during render |
useEffect invocation | Runs once | Runs twice with a forced cleanup in between | Detects missing cleanup causing memory leaks or duplicate subscriptions |
componentDidMount (class) | Invoked once | Invoked twice in development mode | Helps catch side effects that assume single mount |
Side effect detection | Not enforced | Actively exposed via repeated execution | Prevents bugs from unsafe side effects in render or lifecycle |
Production impact | None | Strict mode logic stripped from builds | No effect on production performance or behavior |
By understanding how strict mode in React triggers these behaviors, you can write cleaner, more predictable components.
Code Example: React Strict Mode in Action
import React, { useState, useEffect } from 'react';
function Counter() {
const [count, setCount] = useState(0);
useEffect(() => {
console.log('Effect triggered');
return () => {
console.log('Cleanup triggered');
};
}, []);
return <button onClick={() => setCount(count + 1)}>Click me</button>;
}
export default function App() {
return (
<React.StrictMode>
<Counter />
</React.StrictMode>
);
}
Expected Console Output (in development):
Effect triggered
Cleanup triggered
Effect triggered
This output occurs because React strict mode forces the component to simulate mounting, unmounting, and re-mounting. It helps identify effects that are not properly cleaned up, ensuring that your components behave correctly under re-renders and transitions.
Explanation: This React code demonstrates how Strict Mode intentionally runs the useEffect cleanup and setup twice during development to help catch side effects. This double invocation ensures your components properly clean up resources, preventing bugs during re-renders or transitions.
To use React Strict Mode effectively, you need to wrap your components with the < React.StrictMode.StrictMode.StrictMode> component. This enables additional runtime checks and warnings during development. Strict Mode doesn't render any visible UI or impact production builds, but it highlights potential issues like unsafe lifecycle methods, side effects, and deprecated patterns.
You can use React Strict Mode in two ways, depending on your project's size and complexity:
1. Wrapping the Entire Application (Recommended for New Projects)
The best practice is to wrap your entire application at the entry point (typically index.js). This ensures that all components are monitored under React strict mode from the beginning.
Example:
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App";
const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
Why This Matters:
This method helps enforce consistency across your app and detects problems early in the development cycle. It's especially useful when starting a project with modern React practices in mind. However, be aware that Strict Mode can cause extra console logs during development and may expose issues in some third-party libraries, which can be confusing but ultimately help improve code quality.
Explanation:
This code initializes a React application by creating a root and rendering the App component inside React.StrictMode. Wrapping the App with StrictMode enables additional development checks without affecting the production build.
2. Wrapping Specific Components (Ideal for Legacy Projects)
If you're migrating a large codebase, you can wrap specific parts of the application, such as feature modules, pages, or new components, in React.StrictMode. This allows you to progressively apply strict checks without breaking legacy code.
Example:
function Dashboard() {
return (
<React.StrictMode>
<UserStats />
<Notifications />
</React.StrictMode>
);
}
Why This Matters:
This modular approach gives you control during migration. You can update and test components incrementally under strict mode in React, making it easier to spot issues without refactoring your entire application at once.
Explanation:
This code wraps the Dashboard component’s children in React.StrictMode, enabling extra development checks for potential issues within UserStats and Notifications. This helps catch bugs early without affecting the production build.
Note: Strict Mode only runs in development mode. It does not affect production builds or introduce runtime overhead in production.
Also Read: Top 28 React Projects for Beginners in 2025 [Source Code Included]
Now that you understand React Strict Mode, let's explore key tools and resources to enhance your development process.
To get the most out of React Strict Mode, you need the right tools and resources that help you identify issues and enforce best practices. This section introduces essential utilities like React DevTools, ESLint plugins, and testing frameworks that work alongside Strict Mode to improve your code quality. Understanding these resources will help you catch problems early and maintain a robust React application.
Next, we'll explore each tool and how it complements React Strict Mode in detail.
1. React Developer Tools (React DevTools)
React DevTools lets you inspect the component tree, watch state and props, and track render behavior. Since React Strict Mode causes some lifecycle methods and functions to run twice during development, this tool helps you see exactly when and how these double renders happen. For example, you can spot unexpected side effects caused by repeated renders that might otherwise go unnoticed.
2. ESLint Plugins for React
Static code analysis with ESLint plugins complements React Strict Mode by catching potential errors before you run your app. Plugins like eslint-plugin-react and eslint-plugin-react-hooks alert you to common mistakes such as missing hook dependencies or usage of deprecated lifecycle methods. This early feedback streamlines your debugging process and ensures your code follows React's best practices.
3. Official React Documentation
React's official docs provide detailed and current explanations about Strict Mode, its checks, and best practices. Referring to this resource ensures you stay informed on how Strict Mode behaves, what new warnings mean, and how to adapt your code to future React versions. It's the best place to find authoritative guidance.
4. Testing Frameworks (e.g., Jest)
React Strict Mode's double rendering in development can expose bugs related to side effects or incorrect state handling. Using testing tools like Jest lets you write automated tests that verify your components work correctly, even under Strict Mode’s stricter conditions. This builds confidence that your app behaves as expected before deploying.
5. Component Visualization Tools (e.g., Storybook)
Storybook and similar tools allow you to build and test UI components in isolation. This isolation helps you debug how components behave under Strict Mode's rendering rules without interference from the full application context. It's a practical way to find and fix UI or state issues early.
Take your React skills to the next level with upGrad’s AI-Powered Full Stack Development Course by IIITB. Gain hands-on experience, work on real projects, and receive expert guidance to master modern frontend tools.
Also Read: ReactJS Developer Salary in India: Trends, Growth, and Insights for 2025
To maximize React Strict Mode, combine it with other debugging tools that enhance your workflow. Let’s compare it with other popular React tools to highlight their distinct roles and benefits.
When working with React, you have several debugging tools at your disposal, each serving different purposes. React Strict Mode focuses on highlighting potential issues in your code during development by adding extra checks and warnings. Unlike other tools, it does not provide interactive inspection or code fixes but works alongside them to improve code quality.
Next, we'll compare React Strict Mode with other popular debugging tools to help you understand their unique roles and how they complement each other.
React DevTools is a powerful browser extension that allows you to inspect and interact with your React component tree in real time. Unlike React Strict Mode, which focuses on detecting potential problems during development, DevTools helps you debug by visualizing component state and props.
Understanding the differences between these tools will help you use them together effectively for a smoother development experience. Below, we explore how React Strict Mode compares directly with React DevTools.
React Strict Mode:
React DevTools:
Core distinctions and synergy:
For example, Strict Mode may flag duplicated API calls due to missing dependencies in useEffect. By adding the missing dependency, you can then use DevTools to confirm that the fix works by checking if the extra renders are stopped and ensuring the component behaves as expected. This synergy between Strict Mode and DevTools makes it easier to track down and resolve issues effectively.
Practical example: Strict Mode flags a component for using an unsafe lifecycle method that causes duplicated API calls. Using React DevTools, you can inspect the component's state and props during each render cycle to confirm that your refactor resolves the problem while maintaining expected behavior.
React Strict Mode and ESLint serve different but complementary purposes in your development process. Strict Mode in React detects potential issues during the component lifecycle and runtime, while ESLint and other linters focus on identifying code quality problems, syntax errors, and enforcing style rules.
Using them together helps you catch a wider range of issues before they affect your application. The following points explain how integrating these tools enhances code reliability and maintainability.
Together, they provide a two-layer defense:
Incorporating both React Strict Mode and linters into your workflow ensures that your code remains robust, maintainable, and aligned with React's best practices.
Also Read: React Native Debugging: Techniques, Tools, How to Use it?
Now that you know how React Strict Mode compares with other tools, let’s explore how it addresses challenges like component stack warnings and deprecation alerts to keep your codebase robust.
React Strict Mode generates component stack and deprecation warnings to help you spot and fix issues early in your app. These warnings show exactly where problems exist within your component tree and notify you about APIs that are no longer supported. Learning to interpret these alerts is crucial for keeping your React code reliable and up to date. Next, we'll explore how to handle these warnings effectively.
Deprecation warnings in React Strict Mode alert you to features or APIs that are outdated and may be removed in future releases. Recognizing these warnings early allows you to update your code and avoid potential issues down the line. This section explains how to identify common deprecation warnings and guides addressing them to keep your application stable and maintainable.
Ignoring deprecation warnings can lead to app instability, unexpected bugs, or difficult-to-fix issues down the line. React Strict Mode flags common deprecated lifecycle methods, outdated API usage, and unsafe patterns that should be refactored promptly.
Here are key insights to understand and address these warnings effectively:
Deprecation warnings explained: These warnings identify React features that are obsolete or will soon be unsupported, such as legacy lifecycle methods like componentWillMount or unsafe string refs.
class MyComponent extends React.Component {
componentWillMount() {
console.log("This method is deprecated");
}
render() {
return <div>Hello World</div>;
}
}
Expected Output:
React Strict Mode logs a warning indicating that componentWillMount is deprecated and suggests using safer alternatives like componentDidMount.
Common deprecated APIs flagged by Strict Mode:
Ignoring the deprecation warnings consequences:
Refactoring example: Replace deprecated lifecycle with safer hooks or methods.
// Deprecated componentWillMount
class MyComponent extends React.Component {
componentWillMount() {
// deprecated code
}
render() {
return <div>Hello</div>;
}
}
// Updated with componentDidMount
class MyComponent extends React.Component {
componentDidMount() {
// recommended code here
}
render() {
return <div>Hello</div>;
}
}
Expected Output:
No deprecation warnings; the component behaves consistently across React versions.
Maintaining awareness of deprecation warnings ensures your React application remains stable, performant, and easier to evolve with the framework. Using React Strict Mode as a diagnostic tool lets you proactively spot and fix these issues early in development.
Handling deprecation warnings effectively is essential to maintain a healthy and future-proof React codebase. This section guides you through identifying deprecated methods flagged by React Strict Mode and outlines practical refactoring strategies. You will also learn about tools and best practices that help track and update outdated code, ensuring your application stays compatible with the latest React standards.
These warnings point out code that uses outdated patterns needing your attention before they cause issues in future React versions.
Here's how you can effectively handle these warnings step by step:
1. Identifying deprecated code:
When React detects a deprecated method during development, it logs a clear message specifying the affected lifecycle or API, for example:
Warning: componentWillReceiveProps has been renamed, and is not recommended for use.
This allows you to pinpoint exactly where changes are needed. To catch these issues earlier in team environments, consider using CI linting rules that enforce consistent coding practices and prevent problematic patterns from slipping through the cracks. This helps build preventive workflows and improves code quality across the team.
2. Refactoring deprecated lifecycle methods:
Replace unsafe lifecycle methods like componentWillReceiveProps with safer alternatives such as getDerivedStateFromProps or React hooks like useEffect.
// Deprecated lifecycle
class Example extends React.Component {
componentWillReceiveProps(nextProps) {
if (nextProps.value !== this.props.value) {
this.setState({ value: nextProps.value });
}
}
render() {
return <div>{this.state.value}</div>;
}
}
// Using getDerivedStateFromProps
class Example extends React.Component {
static getDerivedStateFromProps(nextProps, prevState) {
if (nextProps.value !== prevState.value) {
return { value: nextProps.value };
}
return null;
}
render() {
return <div>{this.state.value}</div>;
}
}
Expected Output:
No deprecation warnings; the component updates state safely and predictably.
3. Using React hooks for better state management:
Functional components with hooks like useEffect provide a modern and cleaner alternative to many deprecated lifecycles.
function Example({ value }) {
const [stateValue, setStateValue] = React.useState(value);
React.useEffect(() => {
setStateValue(value);
}, [value]);
return <div>{stateValue}</div>;
}
Expected Output:
Component updates state without triggering deprecated lifecycle warnings.
4. Tools and resources for tracking deprecations:
Following these practical steps will ensure your codebase stays current, avoiding future breakages and maintaining compatibility with upcoming React releases.
React Strict Mode can sometimes cause issues, especially with third-party libraries or during early development stages. This section helps you identify common causes when Strict Mode breaks your code and offers practical steps to diagnose and fix these problems. You will also learn when it might be appropriate to temporarily disable Strict Mode without compromising overall code quality.
Here's how you can approach troubleshooting and resolving problems caused by Strict Mode:
1. Investigate development console logs carefully:
Strict Mode will output warnings and errors that indicate exactly which component or lifecycle method is causing the problem. Pay close attention to stack traces and messages like:
Warning: Unsafe lifecycle methods will not be called in strict mode.
This information helps pinpoint the root cause.
2. Common mistakes to watch for:
3. Step-by-step resolution process:
4. When to temporarily disable Strict Mode:
In some cases, disabling Strict Mode can be necessary, such as:
Here is how you can conditionally disable Strict Mode:
// Temporarily disable Strict Mode
const Root = () => {
return (
<>
{/* <React.StrictMode> */}
<App />
{/* </React.StrictMode> */}
</>
);
};
Expected Result:
The app runs without Strict Mode's extra warnings or double renders, allowing smoother development during troubleshooting.
Best practice: Re-enable Strict Mode once issues are resolved to ensure your code benefits from its checks and future-proofing.
By following this approach, you can manage and overcome disruptions caused by React Strict Mode while maintaining a clean, reliable codebase.
Also Read: How to Implement Stacks in Data Structures? Stack Operations Explained
Now that you’ve seen how Strict Mode handles stacks and warnings, let’s look at other common issues it helps catch and how to fix them.
React Strict Mode helps you identify common coding issues during development that can affect your app's stability and performance. It highlights unsafe lifecycle methods, unexpected side effects, deprecated APIs, and legacy patterns. Understanding these issues enables you to write safer, more maintainable React code. The following sections explain these problems in detail and offer practical guidance on resolving them.
1. Identifying Unsafe Lifecycle Methods
Legacy lifecycle methods such as componentWillMount, componentWillReceiveProps, and componentWillUpdate are flagged by React Strict Mode because they can cause inconsistent behavior and bugs, especially with asynchronous rendering in React’s concurrent mode.
// Deprecated lifecycle method
class MyComponent extends React. Component {
componentWillReceiveProps(nextProps) {
if (nextProps.value !== this.props.value) {
this.setState({ value: nextProps.value });
}
}
// ...
}
// Updated lifecycle method
class MyComponent extends React. Component {
static getDerivedStateFromProps(nextProps, prevState) {
if (nextProps.value !== prevState.value) {
return { value: nextProps.value };
}
return null;
}
// ...
}
Expected Console Output in Development Mode:
Warning: Unsafe lifecycle methods were found within a strict-mode tree:
componentWillMount: Please update the following components to use safer lifecycle methods instead.
componentWillMount called
componentWillMount called
Explanation:
React Strict Mode double-invokes the componentWillMount method to expose side effects or bugs caused by its unsafe execution. The warning informs you that this lifecycle method is deprecated and should be replaced.
Strict Mode flags the deprecated lifecycle usage to ensure you move towards the safer pattern.
2. Detecting Unexpected Side Effects in Components
React Strict Mode invokes certain functions and lifecycle methods twice (in development) to expose side effects that might cause inconsistent behavior.
import React from 'react';
class SafeComponent extends React.Component {
static getDerivedStateFromProps(nextProps, prevState) {
console.log("getDerivedStateFromProps called");
return null; // No state update in this example
}
componentDidMount() {
console.log("componentDidMount called");
}
render() {
return <div>Safe Lifecycle</div>;
}
}
export default function App() {
return (
<React.StrictMode>
<SafeComponent />
</React.StrictMode>
);
}
Expected Console Output in Development Mode:
getDerivedStateFromProps called
componentDidMount called
Explanation:
Unlike the deprecated lifecycle methods, getDerivedStateFromProps and componentDidMount are called only once per lifecycle in production. However, in Strict Mode (development only), componentDidMount is called twice to simulate mounting and unmounting, ensuring predictable and stable updates without unintended side effects.
3. Highlighting Deprecated String Refs and Legacy API Usage
React discourages using string refs due to their implicit and sometimes unreliable behavior. Strict Mode actively warns when these deprecated ref patterns are used. It's worth noting that some third-party libraries still use string refs, which is why Strict Mode may expose issues developers didn't know existed.
// Deprecated string ref
class MyInput extends React.Component {
render() {
return <input ref="myInput" />;
}
}
// Modern ref with createRef
class MyInput extends React.Component {
constructor(props) {
super(props);
this.inputRef = React.createRef();
}
render() {
return <input ref={this.inputRef} />;
}
}
Note: While both versions render the same <input> element, using string refs will trigger warnings in the console when React.StrictMode is enabled. These warnings help you catch legacy patterns that may break with future React updates. To avoid issues, always use createRef or callback refs for better compatibility and control.
Strict Mode warnings prompt migration from string refs to modern ref patterns to future-proof your code.
4. Preparing for Future React Versions
React Strict Mode serves as a safeguard to keep your codebase compatible with upcoming React releases by flagging APIs and patterns that will be deprecated or removed.
Why this matters:
Tools and resources:
Are you a full-stack developer wanting to integrate AI into your workflow? upGrad’s AI-Driven Full-Stack Development bootcamp can help you. You’ll learn how to build AI-powered software using OpenAI, GitHub Copilot, Bolt AI & more.
Also Read: Top 20 Real-Time React Projects and Ideas for Beginners in 2025
This next section breaks down how React Strict Mode benefits your projects and where it may require careful consideration.
React Strict Mode is a development tool that enforces best practices by activating additional checks and warnings during rendering. It helps you identify deprecated lifecycle methods, unexpected side effects, and unsafe ref usages early, improving code quality and application stability. This section explains the core benefits of Strict Mode and outlines its inherent limitations to set realistic expectations.
Benefits of React Strict Mode
Limitations of React Strict Mode
The extra render and lifecycle calls slow down the development environment, potentially impacting hot reload times and responsiveness. This overhead is not present in production.
Basic Usage Syntax and Best Practices
Wrap your root component with <React.StrictMode> in your entry file (e.g., index.js) to enable strict checks globally:
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
Use this pattern to maximize coverage of Strict Mode’s warnings and to enforce consistent best practices across your app.
Note: This doesn’t produce any visual output. Instead, it activates extra checks and warnings in the console during development to help you catch bugs early.
When migrating large or legacy codebases, consider wrapping specific components individually to isolate and address warnings incrementally.
<React.StrictMode>
<Dashboard />
</React.StrictMode>
Explanation: This code snippet wraps the Dashboard component in React.StrictMode to enable Strict Mode checks only for that specific subtree. It helps isolate potential issues without affecting the entire application.
If you want to learn more about algorithms for native debugging, check out upGrad’s Data Structures & Algorithms. The 50-hour free program helps you gather expertise on stacks, queues, and arrays, which are critical to understanding debugging operations.
Also Read: Top 50 React JS Interview Questions & Answers in 2025
To refine your React skills, structured learning and expert guidance can help you apply best practices more effectively. Here’s what upGrad offers for upskilling.
To grow as a React developer, mastering best practices is essential for writing efficient, maintainable, and scalable code. Learning advanced concepts like React Strict Mode and integrating industry standards can set you apart and prepare you for complex projects. Building this expertise requires structured learning and real-world application.
Many developers struggle with gaps in practical knowledge and staying updated with evolving React patterns, which can slow career progress. upGrad offers tailored courses designed to bridge these gaps, helping you learn React thoroughly while emphasizing best practices that industry leaders expect.
Looking to level up your React skills and understand Strict Mode better? These courses offer practical, in-depth guidance for real-world React development:
Feeling stuck with outdated patterns or missing confidence in advanced React topics? Contact upGrad for personalized counseling and expert insights tailored to your learning goals. Visit your nearest upGrad offline center or reach out today to get started!
Boost your career with our popular Software Engineering courses, offering hands-on training and expert guidance to turn you into a skilled software developer.
Master in-demand Software Development skills like coding, system design, DevOps, and agile methodologies to excel in today’s competitive tech industry.
Stay informed with our widely-read Software Development articles, covering everything from coding techniques to the latest advancements in software engineering.
Reference:
https://citrusbug.com/blog/react-statistics/
900 articles published
Director of Engineering @ upGrad. Motivated to leverage technology to solve problems. Seasoned leader for startups and fast moving orgs. Working on solving problems of scale and long term technology s...
Get Free Consultation
By submitting, I accept the T&C and
Privacy Policy
India’s #1 Tech University
Executive PG Certification in AI-Powered Full Stack Development
77%
seats filled
Top Resources