From 22d9a5e360515e6146704f997dc92f3ba2aa6e94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20St=C3=BCckler?= Date: Wed, 13 Feb 2019 11:24:40 +0100 Subject: [PATCH] Use syntax highlighting for examples --- docs/rules/no-access-state-in-setstate.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/rules/no-access-state-in-setstate.md b/docs/rules/no-access-state-in-setstate.md index 8dfe6e746a..9f907d51aa 100644 --- a/docs/rules/no-access-state-in-setstate.md +++ b/docs/rules/no-access-state-in-setstate.md @@ -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}); } @@ -14,7 +14,7 @@ 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}) ``` @@ -22,7 +22,7 @@ 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})); } @@ -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}) ```