Complete the code to import the useEffect hook from React.
import React, { [1] } from 'react';
The useEffect hook is imported from React to run side effects in functional components.
Complete the code to run a side effect after the component renders.
useEffect(() => { console.log('Component rendered'); [1] });Passing an empty array [] as the second argument makes useEffect run only once after the first render.
Fix the error in the cleanup function of useEffect.
useEffect(() => { const timer = setTimeout(() => {}, 1000); return [1]; });The cleanup function must be a function that React calls to clean up. So return a function that calls clearTimeout.
Fill both blanks to run effect only when count changes and clean up properly.
useEffect(() => { console.log('Count changed:', count); return [1]; }, [[2]]);The effect runs when count changes. The cleanup function logs 'Cleanup' before the next effect.
Fill all three blanks to fetch data on mount, store it in state, and clean up properly.
const [data, setData] = useState(null);
useEffect(() => {
let isMounted = true;
fetch('/api/data')
.then(response => response.json())
.then(json => { if ([1]) setData(json); });
return [2];
}, [3]);This pattern avoids setting state if the component unmounts before fetch finishes. The empty array [] makes the effect run only once on mount.