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

setState update arrow function syntax #9476

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/docs/reference-react-component.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ The first argument is an `updater` function with the signature:
`prevState` is a reference to the previous state. It should not be directly mutated. Instead, changes should be represented by building a new state object based on the input from `prevState` and `props`. For instance, suppose we wanted to increment a value in state by `props.step`:

```javascript
this.setState((prevState, props) => {
return {counter: prevState.counter + props.step};
this.setState(function(prevState, props) {
return { counter: prevState.counter + props.step }
});
```

Expand Down Expand Up @@ -284,8 +284,8 @@ Object.assign(
Subsequent calls will override values from previous calls in the same cycle, so the quantity will only be incremented once. If the next state depends on the previous state, we recommend using the updater function form, instead:

```js
this.setState((prevState) => {
return {counter: prevState.quantity + 1};
this.setState(function(prevState) {
return { counter: prevState.quantity + 1 }
});
```

Expand Down