In some react components, there will be this warning
Can't perform a React state update on an unmounted component.
This is a no-op, but it indicates a memory leak in your application.
To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method”
This is because after writing a method to complete the request, we change the state
payload:values,
callback:res=>{
if(res.code === 0){
notification.success({
message: 'Password updated successfully',
description: `The new password is ${res.data}`,
duration: 0,
});
successed&& successed();
that.setState({
updatePwdModalVisible:false
})
that.getCaptcha();
Solution: using the life cycle hook function: component will unmount, clear the timer
before the component is unloaded
that.pwdErrorTimer = setTimeout(() => {
this.setState({
updatePwdModalVisible:false
})
}, 1000);
componentWillUnmount(){
clearTimeout(this.pwdErrorTimer);
}
Similar Posts:
- Can’t call setState (or forceUpdate) on an unmounted component [How to Solve]
- [Solved] ReactNative Warning: Can’t perform a React state update on an unmounted component
- How to deal with the error “cannot read property ‘set state’ of undefined” in react
- Bootstrap switch Uncaught TypeError: Cannot read property ‘apply’ of undefined
- Uncaught Error: _registerComponent(…): Target container is not a DOM element
- Setting root password after installation of Ubuntu 20.04 LTS
- Three common ways of react event binding and solution can’t update during an existing state transition (such as within ‘render’)
- ERROR 1372 (HY000): Password hash should be a 41-d
- [Solved] Django Run Error: TypeError: object supporting the buffer API required
- How to Solve React-native-gesture-handler Error