chenglou / react-motion

A spring that solves your animation problems.
MIT License
21.68k stars 1.16k forks source link

setState(...): Can only update a mounted or mounting component. #565

Open gongchuncheng opened 5 years ago

gongchuncheng commented 5 years ago

version: 0.5.2 //Transition

didLeave() {
       const { didLeave } = this.props;
       didLeave();
}

<TransitionMotion
       willEnter={this.willEnter.bind(this)}
       willLeave={this.willLeave.bind(this)}
       didLeave={this.didLeave.bind(this)}
       defaultStyles={this.getStyles('before')}
       styles={this.getStyles('after')}>
              { this.renderDom.bind(this) }
</TransitionMotion>

//container

destroyToast() {
     const { node } = this.props;  //node: another container   render to body
     const unmountResult = ReactDOM.unmountComponentAtNode(node);
     if (unmountResult && node.parentNode) {
           node.parentNode.removeChild(node);
     }
}
<Transition
      show={show}
      isAnimate={this.isAnimate}
      type='toast'
      didLeave={this.destroyToast.bind(this)}
>
       <div className="MI_toast-container">
               <div className="MI_toast" >{ message }</div>
        </div>
</Transition>

thanks~

fabiulous commented 5 years ago

This seems to be related to this: https://github.com/chenglou/react-motion/issues/567

The code fixing this unmounting issue is not in npm package manager