You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
According to this guide, all items in the state of a react component have to be serializable. I would like to store a non-plain javascript object, what would be the consequences?
The text was updated successfully, but these errors were encountered:
It's not a requirement, you can put anything in there. However generally it's a good idea to stick to plain objects or, for example, ImmutableJS types. What you usually don't want is having an object in state that is being mutated somewhere deeply inside, as you wouldn't be able to compare previous and next states, for example. It's easier to reason when state is immutable.
That being said, it's not a hard requirement. Put whatever you want there. If it has to be an object that is mutated elsewhere, note that React will have no way to know it changed unless you call setState again with the same object. Also note that you're missing out on potential effortless optimizations with PureRenderMixin if your state contents is mutable since state can no longer be shallowly compared.
According to this guide, all items in the state of a react component have to be serializable. I would like to store a non-plain javascript object, what would be the consequences?
The text was updated successfully, but these errors were encountered: