4 ms·
My initial impression was similar to yours, but after I started using hooks, my opinion changed 180 degrees. I've been slowly converting a rather large React fr
by stickfigure 7y ago
My initial impression was similar to yours, but after I started using hooks, my opinion changed 180 degrees. I've been slowly converting a rather large React frontend to hooks and it solves so many problems.
We used to fetch data with HOCs. That never worked well with typescript and was a big problem when you wanted to use more than one (ie, fetching multiple data sources). With hooks we just add separate hooks for each data source we fetch... and the hooks themselves are much simpler than HOCs.
Like the article mentions, hooks move up a layer of abstraction. I'm purging my brain of all the nitty gritty detail of React component lifecycles, because all I ever really cared about was getting data to update at the right time. And now that's the level I can operate at.
Yeah, it doesn't look like standard object oriented code that we're used to. Maybe they could have chosen a different syntax, dunno. But after you get used to hooks, the grass definitely is greener.
- modwest 7y agoI'm there exactly with you. I could've written this comment myself. Love hooks so much. Excellent abstraction. edit: i guess i'm just supposed to upvote and move on but i'm enthusiastic about this topic :)
- acemarke 7y agoHooks definitely bring a different set of tradeoffs, especially compared to Higher Order Components. I'm a Redux maintainer, and the React-Redux API is a good example of this. The `useSelector` and `useDispatch` hooks are way easier to statically type than `connect` is, but calling those hooks embeds knowledge of Redux directly into the component instead of separating it. I specifically talked about these differences in my post "Thoughts on React Hooks, Redux, and Separation of Concerns" [0] and my ReactBoston 2019 talk on "Hooks, HOCs, and Tradeoffs" [1]. For myself personally, I've completely switched to writing function components as a standard practice, but we've also got a lot of devs who are newer to React and still writing classes. I don't feel a need to force rewriting all of those to function components, although I will probably find some time to let folks know that function components + hooks are a thing. [0] https://blog.isquaredsoftware.com/2019/07/blogged-answers-thoughts-on-hooks/ https://blog.isquaredsoftware.com/2019/07/blogged-answers-th... [1] https://blog.isquaredsoftware.com/2019/09/presentation-hooks-hocs-tradeoffs/ https://blog.isquaredsoftware.com/2019/09/presentation-hooks...
- wilsonrocks 7y agoTotally agree about useState and useDispatch... So much easier! It is true that it beds knowledge in the component, but how likely am I to replace redux in a working app?
- nsenifty 7y agoAdditionally, you can write your own hooks that invoke redux hooks internally and hence provide reusability and separation of concerns.