Amy Blankenship
2 min readSep 12, 2022

--

Hi, Scotty;

Thanks for taking the time to comment.

Plenty of people commented that hooks are "simple" and "easy," both here and on Twitter. I'm glad that you would never do this. IMO, if a feature requires a linter for devs to use it without screwing up, it's too complicated. It saddens me that so many other Frameworks are taking "inspiration" from this monstrosity and dragging this junk in. That's good for React, though, because it means that it won't be alone in having buggy, unmaintainable code, and developers will have nowhere to jump ship to that lacks these problems.

I, personally, think it's easier to colocate your componentDidMount/componentWillUnmount functions where they're right next to each other. Having a lot of nameless microfunctions gets to be completely illegible. I didn't go into the problem where you _only_ want to ignore the result of a call after your component is unmounted, and not when dependencies change, resulting in a new call. This will be in a future post, but the TL;DR is devs wind up reinventing the deprecated isMounted from Class components with refs.

I'd love to see a reference where you think I've "pulled" the global warming card before, because I am completely unaware of having done so. In fact, it was in researching this article that I realized this was a thing, so if I did previously write about it I somehow wrote about it before I understood it to be true. Which is amazing (go me!)

And it's not theoretical that using hooks "can" cause unnecessary CPU cycles. It absolutely does. Every render, every function in a useEffect, every function in a useMemo, every function in a useCallback is created even if it will never execute. Sometimes these functions are created even when a render doesn't even happen. That's not unknown. And maybe you don't find the issue compelling, and that' fine. Others will.

--

--

Amy Blankenship
Amy Blankenship

Written by Amy Blankenship

Full Stack developer at fintech company. I mainly write about React, Javascript, Typescript, and testing.

Responses (1)