News for hackers. Stuff that matters.
Re:Understanding UseMemo and UseCallback by michaelsalim on Tuesday August 30, 2022 @05:11PM (#32655126)
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

Re:Understanding UseMemo and UseCallback by ummonk on Tuesday August 30, 2022 @07:57PM (#32656696)
> 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.

Exactly. I’d rather write the code myself than have to review the code of someone who can’t understand such a basic set of concepts.

Re:Understanding UseMemo and UseCallback by mmmpop on Tuesday August 30, 2022 @08:54PM (#32657083)
But see, you're not thinking enterprise.
Re:Understanding UseMemo and UseCallback by foomatic on Wednesday August 31, 2022 @12:51AM (#32658493)
"useCallback" is not very intuitive naming. I'd guess a fair bit of the confusion could be attributed to this alone. Could have been useMemoizedValue useMemoizedCallback at least. The whole useXXX naming convention is also unintuitive.
Re:Understanding UseMemo and UseCallback by adamredwoods on Wednesday August 31, 2022 @01:29AM (#32658716)
Or the term "side effect" (especially in a language that does not enforce return types): https://dev.to/ruizb/side-effects-21fc
Re:Understanding UseMemo and UseCallback by epmatsw on Tuesday August 30, 2022 @07:24PM (#32656469)
I’d argue that useReducer and maybe even useRef most people could get away without knowing.
Re:Understanding UseMemo and UseCallback by postalrat on Tuesday August 30, 2022 @10:34PM (#32657689)
useRef is pretty important. useReducer though could be removed and I wouldn't notice.
Re:Understanding UseMemo and UseCallback by michaelsalim on Thursday September 01, 2022 @09:39PM (#32685630)
I'm inclined to agree with you since I don't use useReducer as well. But there are projects that are littered with that -w-