useMemo | useCallback |
---|---|
Memoizes a value (result of a function) | Memoizes a function |
Memoized value | Memoized function reference |
When we need to memoize a calculated value | When we need to memoize a function |
Recalculates when any dependency changes | Recreates the function only when any dependency changes |
Example: Memoizing the result of expensive computations | Example: Memoizing event handler functions to prevent re-renders |