Skip to content

Commit

Permalink
[Docs] no-access-state-in-setstate: update grammar
Browse files Browse the repository at this point in the history
  • Loading branch information
neaumusic authored and ljharb committed Sep 24, 2019
1 parent 4a05fa2 commit 3124ce0
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions docs/rules/no-access-state-in-setstate.md
Expand Up @@ -11,12 +11,12 @@ function increment() {
}
```

If these two `setState` operations is grouped together in a batch it will
look be something like the following, given that value is 1:
If two `setState` operations are grouped together in a batch, they
both evaluate the old state. Given that `state.value` is 1:

```javascript
setState({value: 1 + 1})
setState({value: 1 + 1})
setState({value: this.state.value + 1}) // 2
setState({value: this.state.value + 1}) // 2, not 3
```

This can be avoided with using callbacks which takes the previous state
Expand Down

0 comments on commit 3124ce0

Please sign in to comment.