- Home
- /
- Tutorials
- /
- React Tutorial
- /
- Memoisation in React
Performance
Memoisation in React
Re-rendering is not slow. React re-runs a function and compares the result - that is cheap. Memoise when you have measured a problem, not because a component renders often.
The three tools
React.memo- skip re-rendering a component when its props are unchanged.useMemo- reuse a computed value between renders.useCallback- reuse a function's identity between renders.
All three trade memory and complexity for skipped work. All three are pointless if the work they skip was cheap to begin with.
Why memo alone often does nothing
React.memo compares props by identity. If the parent passes an inline arrow or object literal, that prop is new on every render and the memo never matches.
memo defeated, then working
jsx
