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

Clarify immutable state #9920

Closed
wants to merge 1 commit into from
Closed

Clarify immutable state #9920

wants to merge 1 commit into from

Conversation

coryhouse
Copy link
Contributor

State is described as immutable here:

"Never mutate this.state directly, as calling setState() afterwards may replace the mutation you made. Treat this.state as if it were immutable."

However, on the Immutability Helper page, state is described as optionally mutable:

"React lets you use whatever style of data management you want, including mutation."

I've provided a suggestion for clarification.

Before submitting a pull request, please make sure the following is done:

  1. Fork the repository and create your branch from master.
  2. If you've added code that should be tested, add tests!
  3. If you've changed APIs, update the documentation.
  4. Ensure the test suite passes (npm test).
  5. Make sure your code lints (npm run lint).
  6. Format your code with prettier (npm run prettier).
  7. Run the Flow typechecks (npm run flow).
  8. If you added or removed any tests, run ./scripts/fiber/record-tests before submitting the pull request, and commit the resulting changes.
  9. If you haven't already, complete the CLA.

State is described as immutable [here](https://facebook.github.io/react/docs/react-component.html#state):

"Never mutate this.state directly, as calling setState() afterwards may replace the mutation you made. Treat this.state as if it were immutable."

However, on the Immutability Helper page, state is described as [optionally mutable](https://facebook.github.io/react/docs/update.html#overview):

"React lets you use whatever style of data management you want, including mutation."

I've provided a suggestion for clarification.
@@ -19,7 +19,7 @@ var update = require('react-addons-update'); // ES5 with npm

## Overview

React lets you use whatever style of data management you want, including mutation. However, if you can use immutable data in performance-critical parts of your application it's easy to implement a fast [`shouldComponentUpdate()`](/react/docs/react-component.html#shouldcomponentupdate) method to significantly speed up your app.
React lets you use whatever style of data management you want, including mutation. However, React's state should be treated as immutable. Immutable data makes it easy to implement a fast [`shouldComponentUpdate()`](/react/docs/react-component.html#shouldcomponentupdate) method to significantly speed up your app.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm worried this might be too specific since the original sentence covered immutable data in props and context as well.

@bvaughn
Copy link
Contributor

bvaughn commented Oct 8, 2017

Thank you for filing this PR!

I'm sorry to be the bearer of bad news, but the documentation and source code for reactjs.org now lives in a different repository: reactjs/reactjs.org. (For more info on why we made this move, see issue #11075.)

Would you be willing to re-open this PR on the new repo? I promise we'll review it quickly!

@bvaughn bvaughn closed this Oct 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants