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

Use syntax highlighting for examples in "no-access-state-in-setstate" #2160

Merged
merged 1 commit into from
Feb 14, 2019
Merged
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/rules/no-access-state-in-setstate.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Such usage of `this.state` might result in errors when two state calls are
called in batch and thus referencing old state and not the current
state. An example can be an increment function:

```
```javascript
function increment() {
this.setState({value: this.state.value + 1});
}
Expand All @@ -14,15 +14,15 @@ 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:

```
```javascript
setState({value: 1 + 1})
setState({value: 1 + 1})
```

This can be avoided with using callbacks which takes the previous state
as first argument:

```
```javascript
function increment() {
this.setState(prevState => ({value: prevState.value + 1}));
}
Expand All @@ -33,7 +33,7 @@ even when things happen in batches. And the example above will be
something like:


```
```javascript
setState({value: 1 + 1})
setState({value: 2 + 1})
```