Complete the code to import the useCallback hook from React.
import React, { [1] } from 'react';
The useCallback hook is imported from React to memoize functions and optimize performance.
Complete the code to memoize the handlePress function using useCallback with an empty dependency array.
const handlePress = [1](() => { console.log('Button pressed'); }, []);
useCallback memoizes the function so it doesn't get recreated on every render.
Fix the error in the dependency array to correctly update the memoized function when count changes.
const increment = useCallback(() => {
setCount(count + 1);
}, [[1]]);The dependency array must include count so the function updates when count changes.
Fill both blanks to create a memoized callback that uses userId inside and includes it in dependencies.
const fetchUserData = useCallback(() => {
fetchData([1]);
}, [[2]]);The callback uses userId inside, so userId must be included in the dependency array to avoid stale closures. fetchData is stable.
Fill all three blanks to create a memoized function that toggles a boolean state and depends on isActive.
const toggleActive = useCallback(() => {
[1](![2]);
}, [[3]]);The function calls setIsActive with the opposite of isActive. The dependency array must include isActive so the function uses the current value and avoids stale closures. setIsActive is stable.