Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Component throws on unmount #1

Closed
otbe opened this issue May 30, 2017 · 2 comments
Closed

Component throws on unmount #1

otbe opened this issue May 30, 2017 · 2 comments

Comments

@otbe
Copy link
Contributor

otbe commented May 30, 2017

Hi,

very nice tilt component, works very well!
I guess there is a problem while unmounting Tilt. It is possible that some of the delayed executions (via setTimeout/requestAnimationFrame) will be executed after the component is unmounted, which will result in a React warning caused by setState calls.

Something like

Warning: setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op. Please check the code for the Tilt component.

I was able to solve this problem by adding some tear down logic:

componentWillUnmount() {
   clearTimeout(this.transitionTimeout);
   cancelAnimationFrame(this.updateCall);
}

Should I prepare a PR?

Thanks!

@jonathandion
Copy link
Owner

Hey Benjamin,

Thank you for your feedback and for the quick fix.

@sahilchopra
Copy link

Hi

I am getting same error

Warning: setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op. Please check the code for the Tilt component.

on reset function
` }, {
key: 'reset',
value: function reset() {
var _this2 = this;

  window.requestAnimationFrame(function () {
    _this2.setState(Object.assign({}, _this2.state, {
      style: _extends({}, _this2.state.style, {
        transform: "perspective(" + _this2.settings.perspective + "px) " + "rotateX(0deg) " + "rotateY(0deg) " + "scale3d(1, 1, 1)" })
    }));
  });
}

},`

Even i have added above mentioned logic on unMount

componentWillUnmount() {
clearTimeout(this.transitionTimeout);
cancelAnimationFrame(this.updateCall);
}

Can you please help me in that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants