3 ms·
I will agree that hooks are a sin against all that is good and proper. Stateful "functions" is just so asinine I don't even know where to begin. It's like they
by deckard1 6y ago
I will agree that hooks are a sin against all that is good and proper. Stateful "functions" is just so asinine I don't even know where to begin. It's like they wanted to ride the hype of functional programming, but didn't understand referential transparency. And somehow that is supposed to be better than classes which, by design, are intended to hold state.
Which brings me to where I disagree with you that React team has their act together. If anything, the hooks API is tacit acknowledgement that they messed up on component lifecycles and their original component model and really don't know what they are doing. If you go back even a year earlier, most people seem to have forgotten that they redid their entire set of lifecycle methods before scraping it all for hooks. They haven't been able to get a stable API together because, architecturally-speaking, they don't know what they are doing.
The only alternative explanation is that hooks is the React team trying to remain relevant through a misguided API "refresh". Which is definitely not a good look for anyone wanting to take a framework seriously. Outside of Facebook, literally no one has the money to rewrite their app every year. Hooks aren't even backwards compatible. It's not even self-compatible with its current version! Since you can't mix hooks and classes. Just insane.
- xwdv 6y agoReact hooks are just syntactic sugar. You can replicate the entire behavior in a purely functional way if you want, but nobody has time for that.
- j-krieger 6y ago> Stateful "functions" is just so asinine I don't even know where to begin So, a closure? I see gripes about hooks mostly on hn. Most of the industry loves it, and for good reason. There is nothing to „understand“ about hooks. You don‘t have to think about what should happen when. Just use hooks to get what you want and forget the rest. If anything, it‘s easier than before.
- datagram 6y agoI personally love hooks, but I can't agree with the claim that "there is nothing to understand about hooks." For starters, they have to be used in a specific way, or else it causes bugs[1]. And there are plenty of other potentially non-obvious things in the (lengthy) FAQ[2]. Once you understand how hooks work they're much easier to work with than class components, but there's definitely a learning curve to using them correctly for anything beyond the simplest use cases. [1]: https://reactjs.org/docs/hooks-rules.html https://reactjs.org/docs/hooks-rules.html [2]: https://reactjs.org/docs/hooks-faq.html https://reactjs.org/docs/hooks-faq.html
- unchar1 6y ago> Stateful "functions" is just so asinine I don't even know where to begin I feel like the React team did a bad job at communicating that the functions are still stateless. The functions themselves never hold state, they just access the state that react holds for each component through hooks. I think this confusion is further fueled by the fact that most people feel render () { return <Button /> } calls the `Button` function inside `render`, but what it actually does is that it registers the `Button` function in React, telling it "here's how you can create what I want", it doesn't actually call the function. The actual call is done by React, if and when it wants to. Hooks extends that idea by letting you say "Here's how I want to update my component". The component functions you write in React are a "description" telling React how to create that component. With hooks you can now "describe" how to update that component with new changes. I feel like hooks force you to let go of the control you thought you had with class-based components. Whether that's a good thing is up upto you.