File tree 1 file changed +2
-2
lines changed
1 file changed +2
-2
lines changed Original file line number Diff line number Diff line change @@ -4,15 +4,15 @@ On the Async nature of setState()
4
4
## Gist:
5
5
React batches updates and flushes it out once per frame (perf optimization)
6
6
However, in some cases React has no control over batching, hence updates are made synchronously
7
- eg. eventListeners, Ajax, setTimeout and similar Web APIs
7
+ e.g. eventListeners, Ajax, setTimeout and similar Web APIs.
8
8
9
9
10
10
### Main Idea
11
11
setState() does not immediately mutate this.state but creates a pending state transition.
12
12
Accessing this.state after calling this method can potentially return the existing value.
13
13
There is no guarantee of synchronous operation of calls to setState and calls may be batched for performance gains.
14
14
15
- Run the below code and you will make the following observations:
15
+ #### Run the below code and you will make the following observations:
16
16
17
17
You can see that in every situation (addEventListener, setTimeout or AJAX call) the state before and the state after are different.
18
18
And that render was called immediately after triggering the setState method. But why is that?
You can’t perform that action at this time.
0 commit comments