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

Calling setState without getInitialState throws when using PureRenderMixin #3316

Closed
ianobermiller opened this issue Mar 5, 2015 · 4 comments · Fixed by #3317 or FormidableLabs/radium#255

Comments

@ianobermiller
Copy link
Contributor

Without getInitialState, this.state is null, which causes this line in shallowEqual to throw.

if (objB.hasOwnProperty(key) && !objA.hasOwnProperty(key)) {

Fix is to make shallowEqual bail if either argument is falsey (or not an object if we want to be very safe).

@sophiebits
Copy link
Collaborator

Is this with PureRenderMixin?

@ianobermiller
Copy link
Contributor Author

Yes, I meant to link to the jsbin: http://jsbin.com/hogike/1/edit?html,js,console,output

I'm putting together a PR now.

@ianobermiller ianobermiller changed the title Calling setState without getInitialState throws Calling setState without getInitialState throws when using PureRenderMixin Mar 5, 2015
@jimfb
Copy link
Contributor

jimfb commented Mar 5, 2015

It is potentially worth noting that getInitialState is likely to become required for stateful components in the near future. See #3236 (comment)

It is already the case that any component calling setState() should ideally be specifying a getInitialState().

@joshbedo
Copy link

@JSFB I definitely think it makes sense to make getInitialState required for stateful components +1

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