Skip to content

Instantly share code, notes, and snippets.

@TidbitsJS
Created August 26, 2021 19:18
Show Gist options
  • Save TidbitsJS/0a39bb33cad85146cb254ab74c271a74 to your computer and use it in GitHub Desktop.
Save TidbitsJS/0a39bb33cad85146cb254ab74c271a74 to your computer and use it in GitHub Desktop.
Don'ts in useEffect
// this does not work, don't do this:
React.useEffect(async () => {
const result = await doSomeAsyncThing()
// do something with the result
})
// this works:
React.useEffect(() => {
async function effect() {
const result = await doSomeAsyncThing()
// do something with the result
}
effect()
})
// or even this works:
React.useEffect(() => {
doSomeAsyncThing().then(result => {
// do something with the result
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment