When used for cheap computations, without a memoized child, or as a default across the codebase. Memoization itself has overhead, so it should be used only where a real bottleneck is measured, not preemptively.
useMemo, useCallback, useRef Interview Questions for React
When does memoization hurt React performance?
The answer
More FAQs in useMemo, useCallback, useRef Interview Questions for React
useMemo memoizes a value; useCallback memoizes a function reference. Use useMemo for expensive computations and useCallback for stable functions passed to memoized children.
useRef returns a mutable object that persists across renders without triggering re-renders. useState triggers a re-render when it changes. Use useRef for DOM references and mutable values that should not drive the UI, and useState for values that should.
For expensive computations that would otherwise run on every render, like sorting a large list. Also to keep an object reference stable for memoized children. Measure first, since memoization is not free.
Still have questions?
Browse all our FAQs or reach out to our support team
Want to upskill yourself?
Your learning library
Small steps. Big possibilities.
Find your next course. Build something great.