You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+29-7
Original file line number
Diff line number
Diff line change
@@ -773,14 +773,36 @@
773
773
774
774
12. ### What is the purpose of callback function as an argument of `setState()`?
775
775
776
-
The callback function is invoked when setState finished and the component gets rendered. Since `setState()`is **asynchronous** the callback function is used for any post action.
776
+
`SetState` is an `asynchronous method`. `Asynchronous` means that the remaining code will get executed while the current action is being performed. Whereas `synchronous` code will block the code execution while the current action is being performed. So, if you want an action to be performed only after the state has been updated you can make use of a call back function. This `callback function` is put as an argument to setstate method. This is the exact purpose of defining a callback function as an argument of setState.
777
777
778
-
**Note:** It is recommended to use lifecycle method rather than this callback function.
779
-
780
-
```javascript
781
-
setState({ name:"John" }, () =>
782
-
console.log("The name has updated and component re-rendered")
0 commit comments