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.