Similar to useMemo
, the useCallback
hook also uses memoization internally in order to improve application performance. The difference is the type of value the two hooks return: while useMemo
returns a memoized value, useCallback
returns a memoized function.
This allows you to create memoized functions and pass them as props between components without having to repeatedly define the caching mechanism in order to avoid expensive, repetitive computations:
// Returns a memoized function
const memoizedFunction = useCallback(() => {
// Define function logic
}, [data])