memo – React
memo – React
v19
memo
memo lets you skip re-rendering a component when its props are
unchanged.
Reference
memo(Component, arePropsEqual?)
Usage
Troubleshooting
Reference
memo(Component, arePropsEqual?)
https://react.dev/reference/react/memo 1/11
20/02/2025, 09:20 memo – React
Parameters
Component : The component that you want to memoize. The memo does
not modify this component, but returns a new, memoized component
instead. Any valid React component, including functions and forwardRef
components, is accepted.
Returns
component provided to memo except that React will not always re-render it
when its parent is being re-rendered unless its props have changed.
Usage
https://react.dev/reference/react/memo 2/11
20/02/2025, 09:20 memo – React
parent re-renders so long as its new props are the same as the old props.
Such a component is said to be memoized.
To memoize a component, wrap it in memo and use the value that it returns in
place of your original component:
A React component should always have pure rendering logic. This means
that it must return the same output if its props, state, and context haven’t
changed. By using memo , you are telling React that your component complies
with this requirement, so React doesn’t need to re-render as long as its props
haven’t changed. Even with memo , your component will re-render if its own
state changes or if a context that it’s using changes.
https://react.dev/reference/react/memo 3/11
20/02/2025, 09:20 memo – React
</label>
Show more
Note
DEEP DIVE
Show Details
https://react.dev/reference/react/memo 4/11
20/02/2025, 09:20 memo – React
Even when a component is memoized, it will still re-render when its own
state changes. Memoization only has to do with props that are passed to the
component from its parent.
Show more
https://react.dev/reference/react/memo 5/11
20/02/2025, 09:20 memo – React
If you set a state variable to its current value, React will skip re-rendering
your component even without memo . You may still see your component
function being called an extra time, but the result will be discarded.
function handleClick() {
setTheme(theme === 'dark' ? 'light' : 'dark');
}
Show more
https://react.dev/reference/react/memo 6/11
20/02/2025, 09:20 memo – React
When you use memo , your component re-renders whenever any prop is not
shallowly equal to what it was previously. This means that React compares
every prop in your component with its previous value using the Object.is
comparison. Note that Object.is(3, 3) is true , but Object.is({}, {}) is
false .
To get the most out of memo , minimize the times that the props change. For
example, if the prop is an object, prevent the parent component from re-
creating that object every time by using useMemo :
function Page() {
const [name, setName] = useState('Taylor');
const [age, setAge] = useState(42);
https://react.dev/reference/react/memo 7/11
20/02/2025, 09:20 memo – React
function Page() {
const [name, setName] = useState('Taylor');
const [age, setAge] = useState(42);
return <Profile name={name} age={age} />;
}
Even individual values can sometimes be projected to ones that change less
frequently. For example, here a component accepts a boolean indicating the
presence of a value rather than the value itself:
function, which React will use to compare the old and new props instead of
using shallow equality. This function is passed as a second argument to
memo . It should return true only if the new props would result in the same
If you do this, use the Performance panel in your browser developer tools to
make sure that your comparison function is actually faster than re-rendering
the component. You might be surprised.
Pitfall
keep “seeing” the props and state from a previous render inside its
onClick handler, leading to very confusing bugs.
https://react.dev/reference/react/memo 9/11
20/02/2025, 09:20 memo – React
Troubleshooting
React compares old and new props by shallow equality: that is, it considers
whether each new prop is reference-equal to the old prop. If you create a new
object or array each time the parent is re-rendered, even if the individual
elements are each the same, React will still consider it to be changed.
Similarly, if you create a new function when rendering the parent component,
React will consider it to have changed even if the function has the same
definition. To avoid this, simplify props or memoize props in the parent
component.
PREVIOUS
lazy
NEXT
startTransition
https://react.dev/reference/react/memo 10/11
20/02/2025, 09:20 memo – React
uwu?
Describing the UI
Adding Interactivity
Managing State
Escape Hatches
Community More
Acknowledgements Terms
https://react.dev/reference/react/memo 11/11