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

你好。

  1. App组件中,从appActions取出clearError函数, 通过props传给ErrorToast组件, ErrorToast 组件自然就通过  this.props.clearError 进行调用了。ErrorToast 设计成一个展示型组件,不会和redux中的方法直接有联系的。

   2.  this.timer 是 我们自定义的 ErrorToast 组件实例的一个属性,保存内部创建的timer 计时器实例。 


0
0

React16+Redux实战企业级大众点评Web App

从架构设计到部署上线,带你学习React技术栈与核心思想

1071 学习 · 306 问题

查看课程