Complete the code to run the effect only once after the component mounts.
useEffect(() => {
console.log('Component mounted');
}, [1]);Using an empty array [] as the dependency list makes the effect run only once after the component mounts.
Complete the code to run the effect whenever the 'count' state changes.
useEffect(() => {
console.log(`Count changed: ${count}`);
}, [1]);Including count in the dependency array makes the effect run whenever count changes.
Fix the error in the effect to avoid running infinitely when 'value' changes.
useEffect(() => {
setValue(value + 1);
}, [1]);Using an empty dependency array prevents the effect from running infinitely by not reacting to value changes.
Fill both blanks to run the effect when 'userId' changes and clean up before next run.
useEffect(() => {
const subscription = subscribeToUser([1]);
return () => [2];
}, [userId]);The effect subscribes using userId and cleans up by calling subscription.unsubscribe() before the next effect run.
Fill all three blanks to update document title with count and clean up on unmount.
useEffect(() => {
document.title = `Count: $[1]`;
return () => {
document.title = [2];
};
}, [[3]]);The effect updates the document title with count. On cleanup, it resets the title to 'React App'. The effect runs whenever count changes.