概述
setState是异步的,不保证同步的
1.回调函数
this.setState({current:e.key}, function () {
console.log(this.state.current);
});
2.生命周期
componentDidUpdate(){
console.log(this.state.current);
}
3.定时器
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 ,父组件要
this.closeOrder = this.closeOrder.bind(this);
最后
以上就是单薄蛋挞为你收集整理的react:setState延迟的全部内容,希望文章能够帮你解决react:setState延迟所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复