Skip to content

Commit

Permalink
[Docs] no-access-state-in-setstate: fix example
Browse files Browse the repository at this point in the history
  • Loading branch information
杨俊宁 authored and ljharb committed Jul 23, 2020
1 parent e8d2ce9 commit cadee91
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docs/rules/no-access-state-in-setstate.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ 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: this.state.value + 1}) // 2
setState({value: this.state.value + 1}) // 2, not 3
this.setState({value: this.state.value + 1}) // 2
this.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 cadee91

Please sign in to comment.