4 ms·
Many folks were criticizing hooks when they were introduced. Of course React devs will "prefer" it; they are the idiomatic way to adding state/triggering effec
by toastercat 3y ago
Many folks were criticizing hooks when they were introduced.
Of course React devs will "prefer" it; they are the idiomatic way to adding state/triggering effects in React.
- paulddraper 3y agoThere is zero functionality that has been removed from class-based components. Devs use hooks primarily because hooks are better.
- toastercat 3y ago> There is zero functionality that has been removed from class-based components. No, but the React ecosystem has almost collectively migrated away from class-based components or deprecated support for them. > Devs use hooks primarily because hooks are better. You avoid much of the dependency array issues by using class components. But you have to deal with `this` and it's significantly more keystrokes. It's more of a tradeoff in my opinion.
- paulddraper 3y agoWell yes that's exactly what I said: it had been very very widely adopted
- toastercat 3y agoI don't see where you said that. It sounded to me like you were insinuating that hooks are inherently better than class components, and that zero functionality has been removed from class components, they are still viable (but they have largely been left in the dust by most popular libraries). Also, devs don't use hooks primarily because they are better. They use them because they are idiomatic React in 2023.
- paulddraper 3y agoThat's akin to saying people don't like Taylor Swift's music because it is good, they like it because it is popular. :hmm:
- toastercat 3y agoIt is not akin to saying that. Please argue in good faith [1]. Writing idiomatic React code makes a lot of practical sense (easier-to-find examples e.g. in the docs, wider library support, onboarding newbies). You can choose to use hooks while acknowledging the tradeoffs from class components. [1] https://news.ycombinator.com/newsguidelines.html https://news.ycombinator.com/newsguidelines.html
- uryga 3y ago> zero functionality has been removed from class components yes, exactly! > They use them because they are idiomatic React right, and do you think it'd be easy for a feature to become idiomatic if it wasn't an improvement over the previous patterns?
- ng12 3y agoAs someone who used to use React and now has to grapple with an in-house web framework: hooks are right on the money and offer tools backing some of the best devex in web right now.
- Jcampuzano2 3y agoI've been using React and writing it professionally since early days before they even supported using ES6 classes. I have also answered questions for years on one of Reacts largest discord communities. Hooks were nice when they came out, but woefully under-documented. The fact that decent docs for hooks first development came out literally just this year when hooks have been out for years is kind of a shame. As opposed to useEffect, most other hooks are fairly straightforward, but the fact it years of articles upon articles of mistakes and documentation to explain useEffect to both experienced and non-experienced devs alike shows that it really wasn't that great of an API for end users. In fact the most common topic nowadays is how much you need to avoid useEffect, especially if you're not a library developer. None of this was documented/mentioned when it first came out. Yes it does enable powerful workflows, but plenty of other frameworks/libraries handle the same thing in a nice way with much less drawbacks than react. (ex: automatic dependency tracking, etc) The number of times I have to tell people to stop putting things in effects at all, or that the reason something isn't working is a stale callback due to missing dependencies in my opinion shows that its not really a good API for the average dev to be using.
- dead_alchemy 3y agoYour last paragraph rang so true. Webpack will tell you that you are missing a dependency and ask you to include it or remove it. I feel useEffect is a fine api. It’s not the apis fault if I shot myself in the foot with it.