关于onclick后函数执行两次的问题
来源:3-14 【异步处理】setState的异步开发

幕布斯7094097
2022-10-28
老师好,请问为什么使用这种preState的方式在控制台打印看到console执行了两次呢
this.setState((preState, preProps) => { console.log("打印state", preState.count); return { count: preState.count + 1 }; });
写回答
1回答
-
沉淀____
2022-11-21
//<React.StrictMode> <App /> //</React.StrictMode>);
在严格模式下就会这样
https://zh-hans.reactjs.org/docs/strict-mode.html#ensuring-reusable-state
20
相似问题