React / Next.js

React Performance Optimization

React.memo, useMemo, useCallback, lazy loading, code splitting, React DevTools Profiler

22 interview questionsยท
Senior
1

What is the primary role of React.memo?

Answer

React.memo is a Higher-Order Component that memoizes a component's render output. It performs a shallow comparison of props and skips re-rendering if props haven't changed. Particularly useful for optimizing expensive child components that frequently receive the same props.

2

What is the main difference between useMemo and useCallback?

Answer

useMemo memoizes the result of a function (the returned value), while useCallback memoizes the function itself. useMemo is used to optimize expensive computations, whereas useCallback is used to stabilize function references passed as props, preventing unnecessary re-renders of memoized child components.

3

In which case can using React.memo be counterproductive?

Answer

React.memo can be counterproductive on components that receive different props on every render, because the cost of shallow prop comparison is added without benefit (the component will re-render anyway). It's better to reserve React.memo for components that often receive the same props and have expensive renders.

4

Why use useCallback for a function passed as prop to a component memoized with React.memo?

5

What is the main advantage of code splitting with React.lazy?

+19 interview questions

Master React / Next.js for your next interview

Access all questions, flashcards, technical tests, code review exercises and interview simulators.

Start for free