9 ms·
Agreed. IMO, it all started with Hooks. Things really went downhill from there. useEffect is terrible! Example, how easy it to forget the dependency array?! Bec
by champagnepapi 3y ago
Agreed. IMO, it all started with Hooks. Things really went downhill from there.
useEffect is terrible! Example, how easy it to forget the dependency array?! Because of that, you have to setup linting rules to fix the poor API provided by that hook...
- hotnfresh 3y agoHooks felt like a big make-work project to let folks claim high-impact commits on a project that didn’t really need any of those, anymore.
- politelemon 3y agoWhat does this expression mean, make-work project?
- hotnfresh 3y agoDigging a hole and filling it back up again. Work for the sake of having something to do.
- politelemon 3y agoAh I understand it now thanks. Not an uncommon thing in many places!
- paulddraper 3y agoHN is a funny place. A useful feature that an insane majority of React devs have come to prefer is "downhill." Kids these days.
- toastercat 3y agoMany 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 ago
- danielvaughn 3y agoI find it's mostly the kids who like hooks, and the older devs who've been around since jQuery or further back, who dislike them.
- tshaddox 3y agoFor what it's worth, that's not at all my experience on the teams I've worked with. I was around when hooks were released and it was an immediate and significant improvement to our team at the time.
- Scarblac 3y agoI'm 49 and started with the Commodore 64, and function based components with hooks are so much cleaner than the old class based components, it's unbelievable. The classes had closely related functionality spread out over several different methods making them hard to understand at a glance, function based components are very concise. I think people who dislike hooks tend to overuse useEffect (it's rarely needed) and to do too much inside components rather than inside custom hooks.
- ng12 3y agoMy experiences with jQuery are literally the exact reason why I like React. I strongly suspect most HNers who are overly critical of React (and/or general web framework complexity) have never had to write and then maintain a large web application in jQuery.
- holoduke 3y agoJQuery is just a hammer. Its not a framework. It does provide utilities like selectors, events, triggers, dom manipulation etc. React is a component based framework. It contains pages, routes, state management, caching etc. You cannot compare those two. In a way jQuery is low level just above vanilla. Wheras react has a minimum of 500 execution layers. Thats why its slow and painful in many cases.
- toastercat 3y ago
- deleted 3y ago[deleted]
- bgirard 3y agoI think this is an artifact of HN's voting system. Most readers probably don't have enough karma to even downvote. For the ones that do, guideline discourage downvoting for comments that you disagree with. And I can see why the majority of HN readers would upvote the top level comment. Particularly since it's a popular re-hashed opinion. Top comments aren't a good survey of the opinions of a specific community for that reason.
- meiraleal 3y ago> HN is a funny place. Full of (ex?) React devs. There are way better things out there now if you are starting a project from zero.
- mitemte 3y agoIn my experience, a lot of people don’t actually know how to use hooks correctly and find them frustrating as a result. It depends on what you’re used to, but I find that class based components leave too much room for scattered logic. Let’s not also forget those who abused `shouldComponentUpdate`.
- dead_alchemy 3y agoWait until they find componentDidUpdate and the cascade of if statements to handle what useEffect does very elegantly.
- Gunax 3y agoEvery other framework not only has its own implementation of hooks, but notably: every one of them is faster, smarter, easier to write, or a combination of all three. I agree that useEffect is bad. But there are other SPA frameworks that do things better. In fact, just about any other framework does things better.
- debaserab2 3y agoIn your estimation, what framework has best in class hooks?
- Gunax 3y agoSome alternatives are: Vue3/composition API -- probably the simplest if you're coming from React. Definitely feels like it was inspired by hooks. Svelte/store -- svelte has a term called 'hook' but it's unrelated. The equivalent would be Svelte's store. The other frameworks use something called 'Signals' (Preact, Qwik, Solid, Elm and even Angular/backbone though I don't personally have in depth knowledge of all of these). IMO, I would prefer Svelte if you are adventurous, or Vue if you like React but just want something like 'better React'.
- shirogane86x 3y agoI mean, Svelte/store is something completely different though, isn't it? it's more akin to Jotai/Zustand/Redux and friends than it is to hooks. If you had to compare Svelte with React, the thing "closest" (while stretching that word very much) to hooks would be the `$` reactivity things Svelte does? Because if you want a state management solution, react has that as well (many, in fact). Just not built in, and a lot of them work really well
- orangepanda 3y agoYou dont have to specify the dependency array, it’s an optional optimisation.
- tuukkah 3y agoEffects are not required to be idempotent, so it's not just an optimisation. React documentation has an example where the effect establishes a network connection. Even if there's time to connect between renders, the remote system doesn't necessarily handle such short-lived connections.
- shortcake27 3y agoThis isn’t quite true. If your effect depends on state, that state must be included as a dependency. This is easy to miss, so you install an eslint plugin to warn you about missing dependencies. This causes the opposite problem - adding dependencies unnecessarily to silence the warning. Then you need to ensure those dependencies are stable to avoid running the hook on every render. Or ignore the warning with a comment, and you’re back to square one. It’s all too easy to write an effect that either doesn’t run when it should, or runs when it shouldn’t. This is especially true for inexperienced developers.