React · Middle · Question 7 of 75
How are useCallback(fn, deps) and useMemo related?
- ✓Correct answer:
useCallback(fn, deps)is the same asuseMemo(() => fn, deps) - 2
useCallbackcalls the function, whileuseMemodoesn't - 3
useCallbackworks only with async functions
Explanation
useCallback caches the function itself, useMemo caches the result of calling a function. useCallback doesn't call the passed function or make it run faster. It's useful when the function is passed to a memo component or used as an effect dependency.