useMemo memoizes a calculated value so React can avoid repeating an expensive computation when its dependencies have not changed. It fits performance-sensitive UI work where unchanged output would otherwise slow rendering and degrade user experience. section 7.0 section 7.2
Call useMemo with a calculation function and a dependency array:
- Include every value used by the calculation in the dependency array. section 7.2
- When dependencies match the previous values in the same order, React may return the stored result. section 7.2
- When a dependency changes, React recalculates and stores the new result. section 7.2
- Treat memoization as an optimization, not a guarantee: React may discard its stored value to free memory. section 7.2 section 7.5
- Omitting dependencies reruns the calculation every time; an empty array permits reuse because its values never change, but still does not guarantee reuse. section 7.2
Memoizing a bookings grid
BookingsGrid generates grid, session, and date data from the selected bookable and week. Wrapping getGrid in useMemo regenerates that data only when bookable or week.start changes: const {grid, sessions, dates} = useMemo(() => bookable ? getGrid(bookable, week.start) : {}, [bookable, week.start]); The component still uses useState for bookings and errors and useEffect for fetching data. section 7.4.4
A figure visualizes the useMemo call with its calculation function and dependency list. section 7.2



