clearError
来源:7-10 前端架构之抽象3:通用错误处理

JackieLu
2020-03-31
componentDidMount(){
this.timer = setTimeout(()=>{
this.props.clearError();
},3000)
}
componentWillUnmount(){
if(this.timer){
clearTimeout(this.timer)
}
}
1.想问一下,为什么在componentDidMount里要写this.props.clearError呢?不是应该调用mapDispatch里的appActions吗?
2. this.timer是什么含义呢?
谢谢解答!
写回答
1回答
-
艾特老干部
2020-04-15
你好。
App组件中,从appActions取出clearError函数, 通过props传给ErrorToast组件, ErrorToast 组件自然就通过 this.props.clearError 进行调用了。ErrorToast 设计成一个展示型组件,不会和redux中的方法直接有联系的。
2. this.timer 是 我们自定义的 ErrorToast 组件实例的一个属性,保存内部创建的timer 计时器实例。
00
相似问题