Complete the code to create a state variable using React hooks.
const [count, setCount] = [1](0);
The useState hook creates a state variable and a function to update it, which triggers re-rendering.
Complete the code to run a side effect after every render.
useEffect(() => { console.log('Rendered'); }, [1]);Omitting the dependency array or passing undefined causes useEffect to run after every render.
Fix the error in the code that causes unnecessary re-renders.
const memoizedValue = useMemo(() => computeExpensiveValue(), [1]);Passing an empty array ensures the expensive computation runs only once, preventing unnecessary re-renders.
Fill both blanks to prevent unnecessary re-renders by memoizing the callback and its dependencies.
const handleClick = useCallback(() => { setCount(count [1] 1); }, [2]);The callback increments count by 1 and depends on count, so it must be included in the dependency array.
Fill all three blanks to create a memoized list of even numbers from props.numbers.
const evenNumbers = useMemo(() => props.numbers.filter(num => num [1] 2 === 0), [2]); const count = evenNumbers[3]length;
The modulo operator % checks for even numbers. The dependency array includes props.numbers so memo updates when numbers change. The dot . accesses the length property.