GithubHelp home page GithubHelp logo

Comments (2)

rogierschouten avatar rogierschouten commented on July 22, 2024

... 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.

skidding avatar skidding commented on July 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.