Created
June 7, 2022 14:29
-
-
Save adityatyagi/7c8f362e16abd5f6eff6ad47dbabacd6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// App.js | |
... | |
... | |
... | |
const [isLoading, setIsLoading] = useState(false); | |
// Button 1 | |
const updateLoading = () => { | |
setIsLoading(true); | |
setIsLoading(false); | |
// setting isLoading to "true" at last | |
setIsLoading(true); | |
// it will still print "false" | |
console.log(isLoading); | |
} | |
// Button 2 | |
const checkLoading = () => { | |
// will print "true" | |
console.log(isLoading); | |
} | |
return ( | |
<div> | |
<button onClick={updateLoading}>Set loading</button> | |
<button onClick={checkLoading}>Check loading</button> | |
</div> | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment