Skip to content

Commit 22d9a5e

Browse files
authored
Use syntax highlighting for examples
1 parent 4270205 commit 22d9a5e

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

docs/rules/no-access-state-in-setstate.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Such usage of `this.state` might result in errors when two state calls are
55
called in batch and thus referencing old state and not the current
66
state. An example can be an increment function:
77

8-
```
8+
```javascript
99
function increment() {
1010
this.setState({value: this.state.value + 1});
1111
}
@@ -14,15 +14,15 @@ function increment() {
1414
If these two `setState` operations is grouped together in a batch it will
1515
look be something like the following, given that value is 1:
1616

17-
```
17+
```javascript
1818
setState({value: 1 + 1})
1919
setState({value: 1 + 1})
2020
```
2121

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

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

3535

36-
```
36+
```javascript
3737
setState({value: 1 + 1})
3838
setState({value: 2 + 1})
3939
```

0 commit comments

Comments
 (0)