我有React生命周期方法如下:
componentWillReceiveProps(nextProps){
if(this.props.totalVehicles !== nextProps.totalVehicles){
this.setState({animation: "cartCount"}, () => setTimeout(() => this.setState({animation: null}), 1000));
}
}
Run Code Online (Sandbox Code Playgroud)
但这给了我:
Warning: setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op. Please check the code for the Header component.
Run Code Online (Sandbox Code Playgroud)
如何在生命周期方法中设置状态而不会出现这些错误?
| 归档时间: |
|
| 查看次数: |
3529 次 |
| 最近记录: |