79673159

Date: 2025-06-20 09:43:40
Score: 1
Natty:
Report link

I just found a PR when a dev used useMemo instead of useCallback to memoize a function. It triggered my curiosity.

Are these two functions inside a React component/hook identical?

let b = 1;

const memoizedFunction = useMemo(
  () => (a) => (a + b),
  [b]
);

const memoizedFunction2 = useCallback(
  (a) => (a + b),
  [b]
);

At first glance, that appears to achieve the same goal.

Reasons:
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (1):
Posted by: Daniel Zegarra Rosario