简体   繁体   English

为什么console.log in react 运行两次

[英]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.每次我在 reactjs 上运行我的代码时,console.log() 在构造函数、渲染或组件中运行两次。 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.你可能在严格模式下使用 React。 Hence it occurs twice.因此它发生了两次。 This wont happen when you use production build of your react app.当您使用 React 应用程序的生产版本时,不会发生这种情况。
This might help you further 这可能会进一步帮助您

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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