chenglou / react-tween-state

React animation.
Other
1.74k stars 70 forks source link

Error when onEnd removed component tweening state #24

Closed natew closed 9 years ago

natew commented 9 years ago

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);
        }
     });
agido-freudenreich commented 9 years ago

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().

chenglou commented 9 years ago

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).

chenglou commented 9 years ago

@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.