Which is a common React performance anti-pattern?

Master ReactJS with our comprehensive test. Practice with multiple-choice questions and detailed explanations. Build your skills for the exam with our engaging format and expert tips!

Multiple Choice

Which is a common React performance anti-pattern?

Explanation:
Creating new functions or objects inside the render path is a common performance pitfall. When you return JSX, any inline arrow function or inline object literal you use gets a fresh reference each time. If you pass these new references as props to child components that rely on shallow prop comparisons (like those wrapped in React.memo) or as dependencies to effects, React will see a change and re-render those children—even if the underlying data didn’t change. This can cascade into many unnecessary renders and extra work. The fix is to keep function and object references stable: define handlers outside render or wrap them with useCallback, and memoize derived values or objects with useMemo (or move them to state or refs). In contrast, memoizing heavy computations, splitting large components into smaller ones, and updating state only when needed are practices that generally support better performance and maintainability.

Creating new functions or objects inside the render path is a common performance pitfall. When you return JSX, any inline arrow function or inline object literal you use gets a fresh reference each time. If you pass these new references as props to child components that rely on shallow prop comparisons (like those wrapped in React.memo) or as dependencies to effects, React will see a change and re-render those children—even if the underlying data didn’t change. This can cascade into many unnecessary renders and extra work. The fix is to keep function and object references stable: define handlers outside render or wrap them with useCallback, and memoize derived values or objects with useMemo (or move them to state or refs). In contrast, memoizing heavy computations, splitting large components into smaller ones, and updating state only when needed are practices that generally support better performance and maintainability.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy