Hey, I didn't understand the concept thoroughly. Can you explain a little bit more.
Some developers tried to use async functions in useEffect and got warnings/bugs with the following code:
useEffect(async () => { await fetch(EXAMPLE_URL) }, []);
I have explained the reason why eslint shows warnings and our cleanup function will not run (because of the async function).
Async functions have to be written in the callback as follows:
useEffect(() => { (async () => { const products = await api.index() setProducts(products) })() }, [])
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.
Hey, I didn't understand the concept thoroughly. Can you explain a little bit more.
Some developers tried to use async functions in useEffect and got warnings/bugs with the following code:
Anti-Pattern: async function directly in the Hook
I have explained the reason why eslint shows warnings and our cleanup function will not run (because of the async function).
Async functions have to be written in the callback as follows: