Complete the code to create a state variable using React hooks.
const [count, [1]] = useState(0);
The useState hook returns a pair: the current state and a function to update it. The convention is to name the update function as set plus the state variable name.
Complete the code to memoize a value and avoid recalculating it on every render.
const doubled = useMemo(() => count * 2, [[1]]);
The dependency array tells React when to recalculate the memoized value. It should include the variables that affect the calculation, here count.
Fix the error in the code to prevent unnecessary re-renders by wrapping the callback with the correct hook.
const increment = [1](() => setCount(count + 1), [count]);
useEffect instead of useCallback.useCallback returns a memoized version of the callback that only changes if its dependencies change. This helps avoid unnecessary re-renders when passing callbacks to child components.
Fill both blanks to create a memoized component that only re-renders when its props change.
const MemoizedButton = [1](Button); export default [2];
useMemo instead of memo for components.memo is a higher-order component that memoizes the wrapped component. The exported component should be the memoized one to avoid unnecessary renders.
Fill all three blanks to optimize a list rendering by memoizing the item renderer and using keys correctly.
const renderItem = [1]((item) => { return <li key={item.[2]>{item.[3]</li>; }, [items]);
useMemo instead of useCallback for functions.useCallback memoizes the function to avoid recreating it each render. The key prop should be a unique identifier like id. The displayed content is the name property.