What does React.memo do?
Model answer
React.memo wraps a component and skips re-rendering it if its props are shallowly equal to the previous ones. It helps for components that are expensive to render and receive the same props often.
It is useless if you pass a new object, array or function as a prop every time, unless those are memoised too.
Learn this topic
React Performance: memo, useMemo, useCallback and When Not to Use Them in the course React.js Full Course: Beginner to Advanced.
Sign in to add your own answer.
More questions
- Why does a component re-render, and is re-rendering always bad?
- What is the difference between useMemo and useCallback?
- What is the React Compiler, and does it replace useMemo and useCallback?
- How do you lazy-load components in React?
- How do you render a very long list efficiently?
- Why can inline objects and functions as props hurt memoisation?