Complete the code to import the React hook used to run code during the mounting phase.
import React, { [1] } from 'react';
The useEffect hook runs code during the mounting phase in React functional components.
Complete the code to run a console log only once when the component mounts.
useEffect(() => {
console.log('Component mounted');
}, [1]);An empty dependency array [] makes useEffect run only once when the component mounts.
Fix the error in the useEffect hook to avoid running the effect multiple times.
useEffect(() => {
fetchData();
}, [1]);Using an empty array [] ensures fetchData runs only once on mount, preventing repeated calls.
Fill both blanks to correctly set up a state and run an effect on mount that updates it.
const [count, [1]] = useState(0); useEffect(() => { [2](5); }, []);
The setter function from useState is setCount. We use it inside useEffect to update the state on mount.
Fill all three blanks to create a component that logs on mount and cleans up on unmount.
import React, { [1] } from 'react'; function Logger() { [2](() => { console.log('Mounted'); return () => { console.log([3]); }; }, []); return <div>Logger Component</div>; }
useEffect runs code on mount and can return a cleanup function that runs on unmount. The cleanup logs 'Component unmounted'.