Complete the code to wrap the component with React.memo for performance optimization.
const MyComponent = () => {
return <Text>Hello World</Text>;
};
export default [1](MyComponent);React.memo is used to wrap a component to memoize it and avoid unnecessary re-renders.
Complete the code to memoize a computed value using useMemo hook.
const total = useMemo(() => {
return items.reduce((sum, item) => sum + item.price, 0);
}, [[1]]);The dependency array should include the variable that, when changed, triggers recomputation. Here, it's 'items'.
Fix the error in the code by choosing the correct way to memoize a callback function.
const handleClick = [1](() => { console.log('Clicked'); }, []);
useCallback is the correct hook to memoize functions, not useMemo.
Fill both blanks to correctly memoize a list of items and avoid re-rendering the child component.
const memoizedItems = [1](() => items, [[2]]);
useMemo memoizes the items array, and the dependency array should watch 'items'.
Fill both blanks to create a memoized component that only re-renders when props change.
const MemoizedComponent = [1](function MyComponent({ [2] }) { return <Text>{name}</Text>; }); export default MemoizedComponent;
React.memo wraps the component, 'name' is destructured from props, and used inside the component.