Yudi Krisnandi
Yudi Krisnandi

Reputation: 485

Why is console.log logging twice inside contructor and render method?

Why is console.log logging twice inside contructor and render method ?

enter image description here

Upvotes: 0

Views: 101

Answers (1)

Rajan Lagah
Rajan Lagah

Reputation: 2528

In simple CRA they do

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

React.StrictMode

Is for developers help. It will show helpful warning and all. For that it need to intentionally double-invoking the following functions:

  1. Class component constructor, render, and shouldComponentUpdate methods
  2. Class component static getDerivedStateFromProps method
  3. Function component bodies
  4. State updater functions (the first argument to setState)
  5. Functions passed to useState, useMemo, or useReducer

You can remove React.StrictMode by <>

And you can learn more about strict mode from here

Upvotes: 3

Related Questions