Capítulo 88 de 116
memo(Component) wraps a component so React skips re-rendering it when its props are shallowly unchanged from the last render — the component-level counterpart to useMemo/useCallback's value/function caching.
const MemoizedComponent = memo(SomeComponent) — optionally with a second argument, a custom comparison function, if shallow equality isn't the right check for that component's specific props.memo compares each prop with Object.is — an object/array/function prop that's recreated fresh every parent render (even with identical contents) still counts as "changed," which is exactly why useMemo/useCallback (Ch 49/59) exist: to give those props stable references so memo's comparison actually succeeds.memo.useMemo, this trades memory/comparison overhead for skipped renders — worth it for components that are expensive to render and receive stable props most of the time, not a blanket "wrap everything" strategy.memo(Component, (prevProps, nextProps) => boolean) — return true to skip re-rendering (props considered equal), false to re-render; useful when a prop's deep equality (not just reference equality) is what actually matters.const Greeting = memo(function Greeting({ name }) {
return <h1>Hello, {name}</h1>;
});
Greeting skips re-rendering on parent re-renders where name hasn't changed, without any custom comparison needed since name is a primitive.memo's default shallow comparison only pays off when the props actually stay reference-stable — pair it with useMemo/useCallback upstream for object/array/function props.memo to skip re-renders while a deferred value lags.