useMemo reuses a calculated value, and useCallback reuses a function reference according to dependencies. Together with React.memo, this may let a child skip rendering.
The demo compares repeated computation with reuse during unrelated parent updates. Memoization has a cost, so measure before adding it everywhere.
When to use
Use it after profiling reveals expensive calculation or unstable references as a bottleneck.