MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Strict Mode and Detecting Unintentional Side Effects0%
Study Materials
React.js for BeginnersProgress 0%
1.1Why React and Single-Page Architecture1.2Setting Up Modern React with Vite1.3React Project Directory Structure and Entry Points1.4Virtual DOM and React Render Cycle Explained
11.1Understanding Common React Errors and Warnings11.2Using React Developer Tools Extension11.3Debugging State Updates and Props in DevTools11.4Strict Mode and Detecting Unintentional Side Effects
HomeTutorialsReact.js for BeginnersStrict Mode and Detecting Unintentional Side Effects
Capstone Project: Comprehensive Task and Todo Application

Strict Mode and Detecting Unintentional Side Effects

Beginner12 min read•Updated: 2026-11-18•By Er. Sumit Kumar (MSK Institute)
Study MaterialsCheatsheet

1. What is React StrictMode?

<React.StrictMode> is a built-in development tool provided by React to highlight potential problems in an application. Like JavaScript's "use strict", it activates additional runtime checks and warnings for its child components.

StrictMode is enabled by wrapping your root component tree inside <React.StrictMode> in src/main.jsx:

1import React from 'react';
2import ReactDOM from 'react-dom/client';
3import App from './App.jsx';
4 
5ReactDOM.createRoot(document.getElementById('root')).render(
6 <React.StrictMode>
7 <App />
8 </React.StrictMode>
9);

2. The Development-Only Guarantee

A critical point of reassurance for every React engineer is: StrictMode checks run ONLY in development mode. StrictMode has zero impact on production builds. It does not add overhead, double-invoke functions, or increase bundle size in production.

3. Why Does StrictMode Double-Invoke Functions?

If you add console.log('Rendering component') inside a component or console.log('Running effect') inside useEffect, you will notice that in development, it logs twice!

1Console Output:
2Rendering component
3Rendering component
4Running effect setup
5Running effect cleanup
6Running effect setup

Why does React do this on purpose?

React's future roadmap and concurrent rendering capabilities rely on components being pure functions. An impure function produces subtle bugs, race conditions, and memory leaks that can be difficult to spot in simple development tests.

To expose accidental side effects, StrictMode deliberately:

  1. 1
    Re-renders component bodies twice: Ensures that component rendering logic is pure and produces the same output without mutating external variables.
  2. 2
    Re-runs effects twice (Mount -> Cleanup -> Mount): Verifies that your useEffect has a valid cleanup function that correctly tears down subscriptions, event listeners, and timers.

4. Catching an Impure Bug with StrictMode

Consider this accidental mutation:

1// ❌ Impure Component
2let guestList = [];
3 
4export default function GuestBadge({ name }) {
5 guestList.push(name); // Mutates an external variable during render!
6 return <div>Guests: {guestList.length}</div>;
7}

In standard production, rendering this with name "Aman" might display Guests: 1.

Under StrictMode in development, React re-renders twice, so guestList.push runs twice! The screen displays Guests: 2!

The developer immediately notices that the count is wrong, uncovering the accidental external mutation that would have caused severe bugs in production.


Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
What is the primary purpose of <React.StrictMode>?
Question 2
Does React StrictMode run in production builds?
Question 3
Why does React StrictMode intentionally run component functions and effects twice in development?
Question 4
If a console.log inside a component body prints twice in your Vite dev server, what is the cause?
Question 5
Can <React.StrictMode> be applied to only a specific section of an application?
Next Lesson

Capstone Project: Comprehensive Task and Todo Application

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Debugging State Updates and Props in DevToolsCapstone Project: Comprehensive Task and Todo Application

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master React.js for Beginners with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext