Loading…
Loading…
Main had a simple PriceSummary with no memoization. A colleague read an article about React optimization and sent a PR that "optimizes" the component: useMemo/useCallback on every line. Walk the diff and explain where memoization is justified and where it's cargo cult.
`useMemo` and `useCallback` are **micro-optimization** tools, not defaults. Rules: **useMemo is justified** when: 1. The calculation is genuinely expensive (>1ms): filtering/sorting a big array, parsing, heavy math. 2. The result is used in another hook's deps (otherwise the effect would fire unnecessarily). **useCallback is justified** when: 1. The callback is passed to a `React.memo` component. 2. The callback is used in an effect's deps. Everywhere else they **hurt**: more overhead than benefit, harder-to-read code. Walk the code and mark where memoization is useless.