【发布时间】:2018-03-25 01:42:13
【问题描述】:
我在使用带有 redux 异步操作的 componentWillReceiveProps 时遇到问题,下面是我的代码和解释。
componentWillReceiveProps(nextProps) {
if(nextProps.job.status === 'applied'){
this.showAppliedDialog()
}
}
componentDidMount() {
this.props.fetchJob(this.props.match.params.id)
}
要求: 当用户单击应用按钮时 - 将用户的工作状态更改为“已申请” - 显示“感谢您的应用程序”对话框以通知用户
错误: 用户的工作状态被应用后,他重新访问路线或刷新当前路线, 显示“感谢您的申请”对话框。
预期: 不要显示“感谢您的申请”对话框
我用回调方法解决了上述问题。但这是唯一的方法吗?我想用减速器代替 继续返回我的异步调度并以回调方式进行
componentDidMount() {
this.props.fetchJob(this.props.match.params.id)
.then(resp => resp.status === 'applied' && this.showAppliedDialog())
}
【问题讨论】:
标签: javascript reactjs redux redux-thunk