setState是异步的,不保证同步的
1.回调函数
复制代码
1
2
3
4this.setState({current:e.key}, function () { console.log(this.state.current); });
2.生命周期
复制代码
1
2
3
4componentDidUpdate(){ console.log(this.state.current); }
3.定时器
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17setTimeout(()=>{ console.log( this.state.current); }, 0); componentDidMount () { console.log('a'); setTimeout(function(){ console.log('b'); },0); console.log('c'); }
最小执行时间windows15毫秒 苹果10毫秒,用最小允许的时间作为setTimeout的时间间隔
父组件将fun传入子组件
子组件调用父组件fun ,父组件要
复制代码
1
2this.closeOrder = this.closeOrder.bind(this);
最后
以上就是单薄蛋挞最近收集整理的关于react:setState延迟的全部内容,更多相关react内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复