Live data from Hacker News

With React 16.8, React Hooks are available in a stable release

reactjs.org

81–90 of 181 posts

Re: With React 16.8, React Hooks are available in a stable release

#81
post #75

Based on the consistent supply of comments sharing hesitation/confusion whenever hooks are talked about, I'm curious. Is this a normal reaction to a new thing that ends up being a very good idea? Are there past examples of this? I can't quite tell if it's a sign that something's off or if this is just normal.

Well, when React first came out no one was convinced by it. It took more than 2 years, I guess, before everybody suddenly got convinced and started claiming it was the best thing and so on.

Not everybody, I still don't consider it the best thing.

I rather use Angular, or eventually VueJS for SPAs, ideally server side with VanilaJS, as not every web site should be a SPA just because.

Re: With React 16.8, React Hooks are available in a stable release

#82
post #71

Earlier quoted context omitted.

But why does Hooks need to be implemented on top of functions and not classes? The way I see it is that Hooks today implements two distinct things: (1) a composable way to handle lifecycle and (2) a custom way to store state. Why can't we have the composable hooks available on React.Component like this? class Foo extends React.Component { constructor(props) { super(props) this.useEffect(…); this.useState(…); // or ma…

How would you pass values between them? Note Hooks execute on every render. That’s their whole point. I explain this here: https://overreacted.io/why-do-hooks-rely-on-call-order/#flaw...

https://codesandbox.io/s/5vvm68k6qp. The custom effects would take functions instead of values and then `useEffect` will be executed by the component. There's certainly some issues in this implementation with regard to how to handle nested state changes, but I think that can be worked out.

Re: With React 16.8, React Hooks are available in a stable release

#83

I don't get it. I thought the main appeal of functions were that they were stateless so you had immutability. We already have classes if we want state, so why is this an improvement? Functions have slightly less overhead maybe? But then why didn't the React team just work on making classes have less overhead? It seems sort of "extra".

Closures are poor man's objects and vice versa.

Re: With React 16.8, React Hooks are available in a stable release

#84
post #13

I don't get it. I thought the main appeal of functions were that they were stateless so you had immutability. We already have classes if we want state, so why is this an improvement? Functions have slightly less overhead maybe? But then why didn't the React team just work on making classes have less overhead? It seems sort of "extra".

Not specific to React, but with CommonJS modules you can use module scope instead of global scope to get private methods and variables, which the function can access via the closure. var foo = 1; var bar = x => x++; module.exports = function baz() { return bar(foo) } I find this much more simple then classes. I even consider it an anti-pattern to make a class for something this simple.

The next dev that comes along and naively imports your module into another part of the app will waste their time trying to figure out why foo keeps getting overwritten by the second instance.

Re: With React 16.8, React Hooks are available in a stable release

#85
post #67
post #38

Earlier quoted context omitted.

Think of series of `useXXX` as declarations, not function calls, then everything will make sense to you. The declaration parts are always static and in the exact same order for the same component. When you see a state less function ToggleButton = () => { const [flag, setFlag] useState(false) const [count, setCount] useState(1) const useEffect(()=> {....}) return setFlag(!flag)>{flag} } View it as a component with two…

Soo, why couldn't this be implemented as: class ToggleButton extends React.Component { flag = useState(this, true) count = useState(this, 0) other = useEffect(this, () => { ... }) render() { return this.flag.set(!this.flag.current)>{this.flag.current} } } Then it's very clear that we have two separate sections: initialization and rendering. There's no longer a hidden state stored somewhere else, but you know that if…

But that’s not how it works. They don’t run during initialization, they run on every render. That’s their whole point and what makes them dynamic.

I tried to explain this here:

https://overreacted.io/why-do-hooks-rely-on-call-order/#flaw...

Re: With React 16.8, React Hooks are available in a stable release

#86
post #25

Are hooks being accepted as a good design by the community? It seems to me that the lack of a parameter explicitly indicating the component and the reliance on hook ordering to match them across calls of the component function make them a bad design, but I might very well wrong and would be happy to be convinced otherwise.

Hooks future depends on its objective: a replacement or an alternative?

I guess even the React team itself doesn't have an answer for this, that is why they are rolling out Hooks relatively cautiously, not forcing it down to the community like what angular does with its 1.x -> 2.0 push, which I consider as a complete disaster that eventually costed it the victory of last framework revolution.

My bet will be on the later. Hooks will become a preference, and there will be a mix of hooks/classes in real world application, since rewriting using Hooks only isn't what most people see will bring immediate benefits. The React community at large from my observation doesn't have a huge issue going forward with the current API, despite being grumpy from time to time.

Re: With React 16.8, React Hooks are available in a stable release

#87

Hooks seem to be a drastic change in how we're going to write React components in the future. I'm quite satisfied with the current way of writing components which is to me is very explicit (with no magic). With Hooks React is taking a different direction from their original motto of explicit design patterns. From the looks of it, Hooks seems like a counter-intuitive design pattern but traditionally that's how most of…

Edit: this is one reason I don’t do the social media thing. I read that in a totally different frame of mind than you wrote it in, probably. I am not one to get all preachy. I personally get caught up in analysis paralysis sometimes because everyone has convincing arguments. It’s because there are many right answers. There’s probably some deeper psychology there... dunno but it’s on me.

No offense, but it would sometimes be good to remember that quote about sufficiently advanced technology being indistinguishable from magic when taking such an authoritative tone.

There are probably some other equally talented developers who do ‘get it’ who might be a little unsure of themselves and continue to hold back and feel like an imposter.

Anyway, that’s not really a call to change or anything. You do you.

But I did want to remind everyone else, especially those unsure of themselves, that those are, like, their opinion... you also do you.

Re: With React 16.8, React Hooks are available in a stable release

#88
post #52

Earlier quoted context omitted.

Nah, HN is jaded as usual but every React dev I've talked to outside HN has been looking forward to this day with excitement ever since hooks landed in alpha. I've yet to see HN get truly excited about anything JS-related, particularly React. Personally I'm excited but I wouldn't bother elaborating my excitement here because I know I'll just attract the usual crowd making unfound assumptions about my experience or co…

Yes, it gets a bit tedious seeing 90% of comments on HN being from people who clearly haven't tried the thing, or even given it any thought or consideration beyond an initial "this is not familiar to me so therefore bad!" kneejerk reaction. It's not a great look for a developer and I don't know why they seem so proud of their close-minded attitude.

Yes, it gets a bit tedious seeing 90% of comments from React fanboys being from people who clearly just repeat each others arguments, or even give no argument at all beyond "I'm assuming you are stupid because people who are not clearly all love this feature". It's not a great look for a developer and I don't know why they seem so proud of their close-minded attitude.

Re: With React 16.8, React Hooks are available in a stable release

#89

Hooks seem to be a drastic change in how we're going to write React components in the future. I'm quite satisfied with the current way of writing components which is to me is very explicit (with no magic). With Hooks React is taking a different direction from their original motto of explicit design patterns. From the looks of it, Hooks seems like a counter-intuitive design pattern but traditionally that's how most of…

I have the exact opposite perception. Previously, I used to convert a function/stateless component, just because I need one transient state and it felt very verbose to switch to class components, while all it needed was one state and corresponding setState. With Hooks, all of them just become more transparent (you explicitly have to hook all the states, not just use one state and add later add more states to track). Though I admit I felt uncomfortable initially, it just feels right once you start working with them. I really like hooks!!!

Re: With React 16.8, React Hooks are available in a stable release

#90

Earlier quoted context omitted.

Yes, it gets a bit tedious seeing 90% of comments on HN being from people who clearly haven't tried the thing, or even given it any thought or consideration beyond an initial "this is not familiar to me so therefore bad!" kneejerk reaction. It's not a great look for a developer and I don't know why they seem so proud of their close-minded attitude.

Yes, it gets a bit tedious seeing 90% of comments from React fanboys being from people who clearly just repeat each others arguments, or even give no argument at all beyond "I'm assuming you are stupid because people who are not clearly all love this feature". It's not a great look for a developer and I don't know why they seem so proud of their close-minded attitude.

I said nothing about loving, or even liking, hooks or React itself. That's not the point. It's weighing in with a completely useless opinion based on a second's thought, over and over again.

There are trade offs and it's interesting to discuss those and to criticise them. But a kneejerk reaction can't go that far.

Post reply on HN