5 ms·
>Hooks are undeniably great I recall seeing far more negative sentiment than positive over the years re. hooks. Maybe it's just me.
by 000ooo000 3y ago
>Hooks are undeniably great
I recall seeing far more negative sentiment than positive over the years re. hooks. Maybe it's just me.
- ricardobayes 3y agoMaybe not hooks in general, but useEffect hooks seem to get hate these days. Even though they were the recommended way just about a year ago?
- Jenk 3y agoHooks are like cooking with really sharp knives - excellent when treated with care and healthy respect for the dangers, but will/can cut you up really badly in a moment of absent-mindedness.
- wildrhythms 3y agoYes, I've seen this firsthand. Side effects can put you in a huge mess, i.e. an effect that triggers another effect, that triggers another effect... and it can be hard to follow that logic if you're unfamiliar with the codebase. I do think it causes confusion compared to the 'setState' class-based components because I can follow all of the setState calls very easily.
- flagrant_taco 3y agoThat's a great analogy and actually gets to my main beef with the whole "I can ship faster with react" argument. When using a sharp knife it's even more important to stick to the principle that slow is steady and steady is fast. It's the same thing with react, and really any of these frontend frameworks that keep piling on complexity. Sure you can ship features fast and if it's throwaway code the great, but if you ever want to reuse or grow it that quick code is a nightmare of tech debt.
- romanovcode 3y agoI think it is more negative towards centralized store and using it for every possible project being ridiculous since hype died down recently.
- cal85 3y agoThe amount of negative vs positive sentiment you see can be misleading. My sense is that a significant minority just don’t get on with them and make a lot of noise about them because the ecosystem sucks now if you don’t like hooks. While that the majority think hooks are somewhere between useful and great, and don’t really comment much on them.
- Jenk 3y agoIndeed, it's selection bias. You're only seeing/hearing those who talk about it, and those who talk the most about it are (probably) from opposing ends of the "positive/negative appreciation of it" scale.
- zkldi 3y agothey're a mess. what the react developers really wanted is a DSL[0], but they couldn't sell that as well so they hacked hooks into JS. The whole things about "rules of hooks" should tip people off that it's sketchy. I mean, have you ever actually thought about how: function Component() { const [state, setState] = useState(1); return <>{state}</> } actually works? How does `useState` know what bit of state to grab? (it's a global store identified by the function you're in, and an index. it's why you can't change the order of hooks nor call them conditionally). Hooks are literally javascript in the sense that they're functions you can call in javascript, but they don't operate under any of the rules people actually think of when they write javascript. If for any `function x() {}`, `if (condition) { x() }` was a fatal error, people would consider that terrible API design and the function shouldn't need to care whether it's called conditionally. Sure, react hooks 'compose' better than class components, but they also don't compose *at all* with anyones mental model of how JS works. What they needed was different syntax or a DSL in general (what svelte does is a lot more understandable, imo). [0]: jsx is a DSL but it's merely one bit of syntax sugar. they needed a hell of a lot more.
- wruza 3y agouseState is basically a local [observable] variable slot in a closure, but defined at runtime in React. That’s why it cannot be conditional. React is an ugly attempt to pretend you’re in a powerful functional language while it’s javascript and you run its core manually and follow the rules for “…reasons”.
- mcv 3y agoI still don't understand what the problem is with class components. They made sense. Now I'm suddenly relying on the behind-the-scenes magic of useState and useEffect. useEffect in particular really messes up my understanding of the flow. Lots of bits of code that may or may not be executed based on the dependency array, and that means my component function is going to be executed several times, each time just to execute another useEffect. It works, but it's not a programming model I like.
- phailhaus 3y ago
- sensanaty 3y agoVue's equivalent (Composition API) handled the hooks concept so much better IMO, by just eliminating 99.95% of the footguns present with Hooks. Obviously Evan had the benefit of hindsight to work with, but still, why people would opt to torture themselves with React when Vue exists will always be an enigma for me