小鹅鹅鹅

Results 5 comments of 小鹅鹅鹅

``` isBatchingUpdates = true setTimeout(() => { this.setState({ count: this.state.count + 1 }) }, 0) isBatchingUpdates = false ``` 看了这段应该就清晰很多了。 react 会在执行前加一个“锁”来标记是否需要批处理, 如上,react加了锁之后立刻就释放了,然后才会执行setTimeout里的setState, 也就是说setTimeout和原生事件会脱离react的控制。 只有在react控制下才会存在批处理,setState才会有“异步”效果。 > 为什么setTimeout里面的setState就不能进行批处理?如果批处理会有什么异常,望解答。

> 在最新的版本里面,React已经默认auto batch updating了 > > [reactwg/react-18#21](https://github.com/reactwg/react-18/discussions/21) 针对这个问题,大家默认讨论版本是react15, fiber之前

> @littleee It seems you are not using English, I've helped translate the content automatically. To make your issue understood by more people, we'd like to suggest using English next...

> 建议创建最小数据的代码,你提供的代码数据太多,很难定位的。 修改好了, 具体问题如上, 感谢小姐姐