Install ahooks and use useAsyncEffect
.
Example:
useAsyncEffect(async () => {
setUser(await getUser());
}, []);
Note: This is bad practice. You should try other techniques instead of trying to run async functions inside useEffect.
Install ahooks and use useAsyncEffect
.
Example:
useAsyncEffect(async () => {
setUser(await getUser());
}, []);
Note: This is bad practice. You should try other techniques instead of trying to run async functions inside useEffect.
For further actions, you may consider blocking this person and/or reporting abuse
Ajmal Hasan -
keploy -
Chris Lojniewski -
Vaibhav Arora -
Top comments (2)
Just why? It a bad approach to fetch data inside useEffect... We have so many better solutions that are in-build in libs or frameworks like next.js, react-router-dom, tanstack query etc, just do not get the point.
That's correct. Let me mark it as bad practice and let's forget about this feature.