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

PureComponent not working with setState inside interval #8624

Closed
davegri opened this issue Dec 22, 2016 · 4 comments
Closed

PureComponent not working with setState inside interval #8624

davegri opened this issue Dec 22, 2016 · 4 comments
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug

Comments

@davegri
Copy link

davegri commented Dec 22, 2016

Do you want to request a feature or report a bug?

Report a possible bug

What is the current behavior?

Calling setState (with new state) insider a setInterval callback does not cause a re-render when using PureComponent. I've tried logging the next and previous state inside shouldComponentUpdate and they show up as identical even though they shouldn't be.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via https://jsfiddle.net or similar (template: https://jsfiddle.net/reactjs/69z2wepo/).

What is the expected behavior?

Component should update

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?

Latest version

@gaearon
Copy link
Collaborator

gaearon commented Dec 22, 2016

Thanks for the report. Unfortunately it is not very helpful without a code example.
This is why the issue template includes this line:

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via https://jsfiddle.net or similar (template: https://jsfiddle.net/reactjs/69z2wepo/).

It is likely that you're mutating the state somewhere. However without code it's impossible to tell.
If you don't provide an example we'll have to close the issue because it is not actionable.

@gaearon gaearon added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Dec 22, 2016
@davegri
Copy link
Author

davegri commented Dec 22, 2016

So when trying to reproduce the bug in a sandbox I realized that we were doing this.state.count++ which was causing the mutation. thanks for the hint!

would it be possible to add warning for state mutations similar to redux-immutable-state-invariant? this was a pretty tough one for us to debug.

cheers

@gaearon
Copy link
Collaborator

gaearon commented Dec 22, 2016

There was an attempt in #8265 but the author didn't continue working on it.

@aweary
Copy link
Contributor

aweary commented Dec 22, 2016

Closing since PureComponent + setState seem to be working fine 👍

would it be possible to add warning for state mutations similar to redux-immutable-state-invariant? this was a pretty tough one for us to debug.

@davegri you can track #2272 for updates on that

@aweary aweary closed this as completed Dec 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug
Projects
None yet
Development

No branches or pull requests

3 participants