Comment

Comment by michaelsalim

While I agree with with that useEffect can be non-intuitive and easy to misuse, I think useCallback is pretty nice to have.

From what I'm aware, it's as you said. It's simply a syntactic sugar for useMemo if you want to memoize functions.

Now if useCallback doesn't exist, you have to use useMemo and pass in a function to the function. Something like `useMemo(() => () => ...)`. Sure if you know what useMemo does then you'll know what it does. But I have a hard time believing that juniors would find that easier to read than useCallback(() => ...).

All I need to say to them is: "Hey, if you want to memoize a function, use useCallback instead". And if I see useCallback used anywhere, I know for sure that it's memoizing a function. Rather than saying: "So you see that there's an extra bracket there? That means that you're returning a function. Yada yada"

There's a grand total of 15 hooks[1], most of which you probably never ever have to use. I would expect all React developer to go through them all to see what they're about.

I would also expect them to know & remember most of the basic ones: useState, useEffect, useContext, useReducer, useCallback, useMemo and useRef. That's a total of 7 functions. If they can't do that then I question the quality of today's developers.

[1] https://reactjs.org/docs/hooks-reference.html

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton