Recall & Review
beginner
What causes unnecessary renders in React components?
Unnecessary renders happen when React re-renders a component even though its output would not change. This can be caused by changing state or props that don't affect the UI, or by passing new object or function references every time.
Click to reveal answer
beginner
How does React.memo help avoid unnecessary renders?
React.memo is a higher-order component that wraps a functional component. It tells React to skip re-rendering the component if its props have not changed, improving performance by avoiding work when not needed.
Click to reveal answer
intermediate
What is the purpose of useCallback in React?
useCallback returns a memoized version of a callback function that only changes if its dependencies change. This helps prevent passing new function references on every render, which can cause child components to re-render unnecessarily.
Click to reveal answer
intermediate
Why should you avoid creating new objects or arrays inside component bodies without memoization?
Creating new objects or arrays inside components causes their references to change every render. If these are passed as props, React thinks the props changed and re-renders child components. Memoizing them with useMemo or useCallback avoids this.
Click to reveal answer
intermediate
What role does useMemo play in avoiding unnecessary renders?
useMemo memoizes the result of a calculation or object creation so React reuses the same value between renders unless dependencies change. This prevents passing new references that cause child components to re-render.
Click to reveal answer
Which React hook helps memoize a function to avoid unnecessary re-renders?
✗ Incorrect
useCallback memoizes functions so their references stay the same unless dependencies change, helping avoid unnecessary renders.
What does React.memo do?
✗ Incorrect
React.memo skips rendering a component if its props are the same as before, improving performance.
Why can passing new object literals as props cause unnecessary renders?
✗ Incorrect
React compares props by reference, so new object literals create new references causing re-renders.
Which hook would you use to memoize a computed value to avoid recalculating it every render?
✗ Incorrect
useMemo memoizes computed values so they are recalculated only when dependencies change.
What is a common sign that a React component is rendering unnecessarily?
✗ Incorrect
Unnecessary renders cause slow performance even though the UI output does not change.
Explain how React.memo, useCallback, and useMemo work together to avoid unnecessary renders.
Think about how React decides to re-render components based on props and function references.
You got /4 concepts.
Describe why creating new objects or functions inside a React component can cause performance issues.
Focus on how React compares props and why stable references matter.
You got /4 concepts.