Live data from Hacker News

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

reactjs.org

71–80 of 181 posts

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

#71

I've read a lot about hooks, the reasoning all makes sense but I'm still not fully getting it at an intuitive level. Like I get that it means you can write functional versions of class based components, an example of a complex class component that has been converted to a function with hooks would be good. The counter example really leaves a lot to the imagination. The examples in https://usehooks.com/ aren't convinci…

A major point of Hooks is that they’re composable — unlike lifecycle methods. You can separate different reusable pieces of logic into Hooks, and then combine them or pass values between them. You can even call the same Hook more than once. I’ve wrote about new possibilities they unlock here: https://medium.com/@dan_abramov/making-sense-of-react-hooks-... Hope this helps.

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 maybe even a top-level API:
         useState(this, …);
       }
    }

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

#72

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…

My litmus test for technology is whether it results in a) fewer lines of code b) simpler code and c) does it make me more productive. My experience with using hooks is that I rip out lots of cruft and it is easier for me to get my head around how to write things so I am more productive. The cost is learning a new paradigm, but the benefit for me was very high.

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

#74

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…

In case you’re curious, I recently wrote up a deep dive on React from first principles that includes Hooks. https://overreacted.io/react-as-a-ui-runtime/ Personally I don’t see them as being either “magic” or “implicit”. You might find my post helpful for conceptualizing how they fit into the picture. (Warning: it is a longread. But it also explains 90% of React on a single page.)

That’s a great read.

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

#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.

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

#76
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.

True. As I read through the blogs about it a third time I'm slowly starting to see what the deal is.

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

#77
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.

Recently wrote a customer dashboard app and hooks were just introduced. I'm glad I went full in with them.

I think they will be the standard going forward.

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

#78
post #71

Earlier quoted context omitted.

A major point of Hooks is that they’re composable — unlike lifecycle methods. You can separate different reusable pieces of logic into Hooks, and then combine them or pass values between them. You can even call the same Hook more than once. I’ve wrote about new possibilities they unlock here: https://medium.com/@dan_abramov/making-sense-of-react-hooks-... Hope this helps.

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...

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

#79
Slightly off-topic, but has any of those who dislike hooks for the added magic seen Svelte.js version 3? It is ridden with magic. Top-level variables in the block are "observable" in the Vue sense of the word and accessible in the block; so whenever they change, the relevant parts of the template get updated. The creator of Svelte says that it's very intuitive, and that developer experience is great. I wonder what your take on that will be.

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

#80
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.

While HN wasn’t convinced last time I posted this, here’s a few posts or sections that explain the static call order thing: https://overreacted.io/why-do-hooks-rely-on-call-order/ https://overreacted.io/react-as-a-ui-runtime/#static-use-ord... https://github.com/reactjs/rfcs/pull/68#issuecomment-4393148... (Persistent Call Index section) Hope this helps, happy to answer questions. We’ve been using Hooks for several m…

I found it especially nice that React told me where I was doing it wrong.
Post reply on HN