Skip to content

Commit a94f16b

Browse files
authored
Merge pull request #113 from sumanpaikdev/patch-1
Highlight a heading and adding a dot.
2 parents e18ac50 + 2b52cdd commit a94f16b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

patterns/19.async-nature-of-setState.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ On the Async nature of setState()
44
## Gist:
55
React batches updates and flushes it out once per frame (perf optimization)
66
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.
88

99

1010
### Main Idea
1111
setState() does not immediately mutate this.state but creates a pending state transition.
1212
Accessing this.state after calling this method can potentially return the existing value.
1313
There is no guarantee of synchronous operation of calls to setState and calls may be batched for performance gains.
1414

15-
Run the below code and you will make the following observations:
15+
#### Run the below code and you will make the following observations:
1616

1717
You can see that in every situation (addEventListener, setTimeout or AJAX call) the state before and the state after are different.
1818
And that render was called immediately after triggering the setState method. But why is that?

0 commit comments

Comments
 (0)