Live data from Hacker News

We memo all the things (2020)

attardi.org

81–84 of 84 posts

Re: We memo all the things (2020)

#81

Earlier quoted context omitted.

The problem with avoiding useCallback is that another hook will bite you: useEffect. If you need to define functions that interact with your component's state, you have to memoize them with useCallback (or useRef) to avoid a useEffect infinite loop. What's even worse is that if functions passed as props are unstable, your useEffect will run every time the parent component renders — meaning that a component can't trus…

hooks in general are a huge footgun. You need to place them at the preamble of your function (and not nested). They have to be named with "use" prefix (worth mentioning is React basically commandeered the entire "use" namespace for their own purposes via lint enforcement, which will bite you in the ass eventually), and they are poorly designed. Take useRef for example. You'd logically expect it to work with useEffect…

In practice, I don't think the "rules of hooks" [1] are a footgun, especially if you use the eslint rule.

I'm confused about your second paragraph. useRef works perfectly fine for keeping a reference stable so as to avoid triggering useEffect. In fact, that's one of the main tools I use to work around the useEffect dependency array.

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

Re: We memo all the things (2020)

#82
post #36

This was in 2020. I assume the team got made redundant in the last year or something. Coinbase has genuinely been the slowest performing website I've used in the past couple of years.

I asked the author on Twitter if this approach was still in place, but didn't get a reply :/

Edit: He did reply: https://twitter.com/steadicat/status/1452686612370915328

Re: We memo all the things (2020)

#84

Earlier quoted context omitted.

The problem with avoiding useCallback is that another hook will bite you: useEffect. If you need to define functions that interact with your component's state, you have to memoize them with useCallback (or useRef) to avoid a useEffect infinite loop. What's even worse is that if functions passed as props are unstable, your useEffect will run every time the parent component renders — meaning that a component can't trus…

I wouldn't say useEffect is a footgun, it just requires realising that React is doing shallow comparisons.

To me, a footgun isn't necessarily something that is hard to understand, but also something that's easy to misuse even if you understand it.
Post reply on HN