News for hackers. Stuff that matters.
Re:Things you forgot because of React by repsilat on Tuesday August 15, 2023 @11:50AM (#37135430)
> Bragging that you can't understand the difference between useMemo and useCallback after reading the docs (one is general memoization and the other is function-specific)

Right, the first argument to useMemo must be a function, but the first argument to useCallback need not. That's what you meant, right?

Re:Things you forgot because of React by ShellfishMeme on Tuesday August 15, 2023 @01:18PM (#37136635)
useCallback makes sure that you don't recreate a function you need in a component at every re-render but only when its dependencies change. It returns a function.

useMemo returns a value which is the result of calling the function it is given once the dependencies change.

So useCallback is basically useMemo called with a function that returns a function.

Re:Things you forgot because of React by repsilat on Tuesday August 15, 2023 @05:47PM (#37139689)
> useCallback ... returns a function.

It returns something with the same type you gave it. If you give it a function it gives you a function back.

In typescript it's declared to take a function but in practice it doesn't check, and can be used to stabilize the identity of anything.

useMemo otoh _does_ only take functions.