4 ms·
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 sa
by michaelsalim 4y ago
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 https://reactjs.org/docs/hooks-reference.html
- epmatsw 4y agoI’d argue that useReducer and maybe even useRef most people could get away without knowing.
- postalrat 4y agouseRef is pretty important. useReducer though could be removed and I wouldn't notice.
- michaelsalim 4y agoI'm inclined to agree with you since I don't use useReducer as well. But there are projects that are littered with that -w-
- ummonk 4y ago> 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.
- mmmpop 4y agoBut see, you're not thinking enterprise.
- foomatic 4y ago"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.
- adamredwoods 4y agoOr the term "side effect" (especially in a language that does not enforce return types): https://dev.to/ruizb/side-effects-21fc https://dev.to/ruizb/side-effects-21fc