Intermediatenote 02 of 1203 reasons · 03 notes
ReactIntermediate
Memoize only expensive work
Use memoization for costly derived values, not as decoration around every expression.
Code example
Copy, adapt, and ship.
Read the numbered lines, copy the complete snippet, then adjust the values for your project.
const visibleRows = useMemo(() => { return rows .filter((row) => row.status === activeStatus) .sort((a, b) => b.score - a.score);}, [rows, activeStatus]);Why this matters
The production reason.
- 01
Memoization is useful when a calculation is expensive or when a stable reference prevents a costly child render.
- 02
Using useMemo everywhere adds dependency noise and can hide simpler data-flow problems.
- 03
Measure or at least identify the expensive operation before adding memoization.
How it holds up outside a demo.
- ReactMemoize filtered, sorted, or grouped lists when they are large.
- TanStack TableMemoize column definitions so the table does not rebuild constantly.
- Next.jsDo heavy data shaping on the server when the browser does not need to own it.
Explore other stacks
Jump into a different technology.
12 React notes on this shelf, and six more stacks beside it.
Use next/image for image optimization
Next.js image optimization starts with next/image sizing, lazy loading, modern formats, and predictable dimensions.
Open the noteAbort stale fetch requests
Cancel outdated browser requests so fast UI changes do not render old data.
Open the noteBuild a CSS gradient generator with code export
A CSS gradient generator should preview color stops, preserve accessible contrast, and export clean CSS code.
Open the noteFix WordPress H1 SEO issues
Fix WordPress SEO issues by keeping one clear H1, escaping template output, and compressing images before WordPress upload.
Open the noteReduce LCP with image optimization
Reduce LCP with image optimization by resizing, converting, and compressing images before they reach production.
Open the noteUse real buttons for actions
If it changes state, use button. If it navigates, use a link.
Open the note