chenglou / react-tween-state

React animation.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error when onEnd removed component tweening state

natew opened this issue · comments

This should probably work:

      this.tweenState('step', {
        endValue: 2,
        duration: this.props.animationDuration,
        onEnd: this.props.onClose
      });

But if props.onClose removes the tweening element I get an error setState on non-mounted component. This fixes it for now:

      this.tweenState('step', {
        endValue: 2,
        duration: this.props.animationDuration,
        onEnd: () => {
          setTimeout(this.props.onClose);
        }
     });

I've the same problem but setting a timeout did not fix it.

I use tweenState in combination with componentWillLeave.

The problem is in _rafCb():

if (!this.isMounted()) {
      return;
    }

At method call the component is still mounted but the state changed till setState() is called.
Quickfix: Add the same check just before setState().

Thanks and sorry for the wait!

Fortunately with React 0.13, setting state after unmounting doesn't throw anymore. The warning's still bothersome though, so I'll make the change @agidoSF suggested. (@natew: your fix didn't work for me either).

@agidoSF @natew I just released v0.0.5, which contains the fix, because this is the last release compatible with React < 0.13 (0.13 actually breaks something in tween-state and I'm fixing it now). Seemed better than to jump straight to supporting only React 0.13+ and leaving people at 0.12 without this fix.