Common components react problems Can not perform a React state update on an unmounted component

These components react in time, have 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 the completion of the request in writing a method to change the state of our state,

  payload: values, 
        the callback: RES => {
           IF (res.code === 0 ) { 
            notification.success ({ 
              Message: 'password update success' , 
              Description: `new password res.data} {` $, 
              DURATION: 0 , 
            }); 
            successed && successed (); 
              that.setState ({ 
                updatePwdModalVisible: to false 
              }) 
            that.getCaptcha ();

Solution: use life cycle hook function:componentWillUnmount,在组件卸载前清除timer

 that.pwdErrorTimer = setTimeout(() => {
              this.setState({
                updatePwdModalVisible:false
              })
            }, 1000);

  

  componentWillUnmount(){
    clearTimeout(this.pwdErrorTimer);
  }

  

Guess you like

Origin www.cnblogs.com/aloneindefeat/p/12106450.html
Recommended