Thanks for sharing. I have some comments
1) you have forgotten to await in your function in the first snippet so it should have been like
const result = await doSomeAction();
2) I think calling directly an async function in useEffect is not recommended. I remember getting an warning the last time I did it.
useEffect(() => { asyncStuff() }, []) const asyncStuff = async () => { setResult(null) setError(null) setLoading(true) try { const result = await doSomeAction(); setResult(result) } catch (e) { setError(e) } finally { setLoading(false) } } Thanks
You're absolutely right on both fronts. I'll update the example. Thanks!
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Thanks for sharing.
I have some comments
1) you have forgotten to await in your function in the first snippet so it should have been like
2) I think calling directly an async function in useEffect is not recommended. I remember getting an warning the last time I did it.
You're absolutely right on both fronts. I'll update the example. Thanks!