Skip to content

Commit 2114385

Browse files
committed
Clarify setState troubleshooting example
1 parent 6d8c199 commit 2114385

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

content/docs/faq-state.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ category: FAQ
1212

1313
### Why is `setState` is giving me the wrong value?
1414

15-
Calls to `setState` are batched, so it is possible to "lose" an update if you call it with the partial object syntax:
15+
Calls to `setState` are asynchronous - don't rely on `this.state` to reflect the new value immediately after calling `setState`. Pass an updater function instead of an object if you need compute values based on the current state (see below for details).
16+
17+
Example of code that will not behave as expected:
1618

1719
```jsx
1820
incrementCount = () => {
@@ -28,7 +30,7 @@ handleSomething() {
2830

2931
See below for how to fix this problem.
3032

31-
### How do I do ordered state updates?
33+
### How do I update state with values that depend on the current state?
3234

3335
Pass a function instead of an object to setState to ensure the call always uses the most updated version of state (see below).
3436

0 commit comments

Comments
 (0)