Reactjs Console.log正在构造函数和React.js中的render函数中打印两次值
为什么console.log在构造函数和呈现函数中打印两次值 这是:Reactjs Console.log正在构造函数和React.js中的render函数中打印两次值,reactjs,constructor,react-class-based-component,Reactjs,Constructor,React Class Based Component,为什么console.log在构造函数和呈现函数中打印两次值 这是: class App extends React.Component { constructor(props) { console.log('Constructor'); super(props) this.state = { counter: 0 } } render() { console.log('render'); return ( <
class App extends React.Component {
constructor(props) {
console.log('Constructor');
super(props)
this.state = {
counter: 0
}
}
render() {
console.log('render');
return (
<div style={{ fontSize: '45px', fontWeight: 'bold' }}>
Counter: {this.state.counter}
</div>
)
}
}
类应用程序扩展了React.Component{
建造师(道具){
console.log('Constructor');
超级(道具)
此.state={
柜台:0
}
}
render(){
console.log('render');
返回(
计数器:{this.state.Counter}
)
}
}
这是由于React.StrictMode
造成的<代码>反应。StrictMode是一个包装器,用于帮助为异步呈现准备应用程序
你可以在这里了解更多