Skip to content

Instantly share code, notes, and snippets.

@adityatyagi
Created June 7, 2022 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adityatyagi/7c8f362e16abd5f6eff6ad47dbabacd6 to your computer and use it in GitHub Desktop.
Save adityatyagi/7c8f362e16abd5f6eff6ad47dbabacd6 to your computer and use it in GitHub Desktop.
// 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