- 有时异步,有时同步(setTimeout、DOM事件)
- 有时合并(对象形式),有时不合并(函数形式)
setState主流程

class DemoLeft extends React.Component { constructor() {...} render() {...} increase = () => { // 开始:处于 batchUpdate // isBatchingUpdates = true; this.setState({ count: this.state.count + 1 }); // isBatchingUpdates = false; }}
increase = () => { // 开始:处于 batchUpdate // isBatchUpdates = true setTimeout(() => { // 此时 isBatchingUpdates 是false this.setState({ count: this.state.count + 1 }) }) // 结束 // isBatchUpdates = false;}
componentDidMount() { // 开始:处于 batchUpdate // isBatchingUpdates = true document.body.addEventListener('click', () => { // 此时 isBatchingUpdates 是 false this.setState({ count: this.state.count + 1 }) console.log(this.state.count); }) // 结束 // isBatchUpdates = false;}
setState 异步还是同步?