Comments (2)
... and I'll also post the answer provided by @gaearon:
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.
from react-guide.
Thanks for adding the answer @rogierschouten. Yes, it's not a framework limitation, but it's a strict guideline we set for our codebase. It works great with Cosmos
from react-guide.
Related Issues (9)
- State can get initial value from parent Component? HOT 2
- Table not rendering on GitHub HOT 2
- Props change does not re render HOT 18
- Are props geometrical properties of a component? HOT 2
- Broken link
- Licensing? HOT 1
- Document component > mixin > lib guidelines
- props cannot change inside Component? HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-guide.