简体   繁体   中英

Why console.log in react runs twice

Everytime I run my code on reactjs, console.log() runs twice in constructor,render, or in the components. Why does it do that?

class App extends Component {
  constructor(props){
    super(props);
    console.log("[App.js] constructor")
  }

You are probably using React in Strict Mode. Hence it occurs twice. This wont happen when you use production build of your react app.
This might help you further

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM