Created
August 26, 2021 19:18
Don'ts in useEffect
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
// 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