我是靠谱客的博主 单薄蛋挞,这篇文章主要介绍react:setState延迟,现在分享给大家,希望可以做个参考。

setState是异步的,不保证同步的
1.回调函数

复制代码
1
2
3
4
this.setState({current:e.key}, function () { console.log(this.state.current); });

2.生命周期

复制代码
1
2
3
4
componentDidUpdate(){ console.log(this.state.current); }

3.定时器

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
setTimeout(()=>{ 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
2
this.closeOrder = this.closeOrder.bind(this);

最后

以上就是单薄蛋挞最近收集整理的关于react:setState延迟的全部内容,更多相关react内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(43)

评论列表共有 0 条评论

立即
投稿
返回
顶部