Last active
August 9, 2022 03:00
-
-
Save JonathonAshworth/291694336cd48c02610570310c33fd07 to your computer and use it in GitHub Desktop.
Cleaning up asynchronous render side effects
This file contains hidden or 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
useEffect(() => { | |
const pFoo = getFoo().then(foo => /* do somthing with our async foo, making sure to return it */); | |
return () => pFoo.then(foo => /* cleanup here will always run after we have gotten our foo and used it */); | |
}); | |
// This is one of the few cases where it makes sense to use raw promises instead of async/await | |
// The power of promises is that you can compose asynchronous logic asynchronously | |
// Afaik that's not possible with async/await? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment