Problem Statement
What is the purpose of useEffect in functional components?
Explanation
useEffect allows you to perform side effects that are not directly related to rendering, such as fetching data or setting up event listeners. You can also return a cleanup function to handle unmounting logic.
Code Solution
SolutionRead Only
useEffect(() => { fetchData(); return () => cleanup(); }, []);Practice Sets
This question appears in the following practice sets: