Live data from Hacker News

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

reactjs.org

51–60 of 181 posts

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

#51
post #45
post #43

This is exciting, and at the same time I wish this came out before writing thousands of lines of code on my React app... I can see the possibilities this brings, and they're much better than the mess of props, local state, redux, and HoCs that we have. But the refactoring needed is just insane. Has anyone gone through something like this and has any tips?

The primary tip is: don't refactor. It's unlikely to solve any problems if you already have working code in which you've already dealt with all the hassles of HoCs and such. You can just start using it in new code to avoid having to deal with it for that.

I follow this sometimes but having a wide range of patterns in the same project feels so dirty in a way... Although it makes sense, refactor only when you need to.

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

#52

The crowd goes mild.

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 complaining about hooks not following best practices (like, I don't know, JSX?).

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

#53
post #41

Earlier quoted context omitted.

I don't know what is there to cheer about the introduction of a feature that offers nothing new.

Hooks offers nothing new over HoC and FaC the same way React offered nothing new over jQuery and EmberJS.

You're being sarcastic but there are enough people around who wouldn't see that at face value.

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

#54

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…

Hooks fix some of the composition headaches you get from render props, which is the current standard for composition (the heritage being HOCs -> render props -> hooks). They're basically mixins with weird syntax.

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

#55

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 thought the same at first, but Dan Abramov and his blog[1] has changed my mind.

[1]: https://overreacted.io/why-do-hooks-rely-on-call-order/

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

#56
post #41

Earlier quoted context omitted.

I don't know what is there to cheer about the introduction of a feature that offers nothing new.

Hooks offers nothing new over HoC and FaC the same way React offered nothing new over jQuery and EmberJS.

That is being unfair to React.

React changed the way developers reason about UI/DOM from imperative to declarative, the holy grail here is that a declarative API allows you to move up your state and have a "single source of truth" and so makes it easy to reason about your application's state at the cost of having more plumbing, for example consider incriminating the value of an input with jQuery (imperative) vs React (generally with Redux).

What Hooks does is move the component's state management from components root a level deeper into hook functions and advocates for reusable state management functions that manages various fragments of your component's state, this I believe is a step backwards in terms of simplifying how you reason about state management in terms of complexity --not lines of code.

I am just not sure if this abstraction is worth it in practice and a good step for React.

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

#57

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

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

#58

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.

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

#59
post #51
post #45

Earlier quoted context omitted.

The primary tip is: don't refactor. It's unlikely to solve any problems if you already have working code in which you've already dealt with all the hassles of HoCs and such. You can just start using it in new code to avoid having to deal with it for that.

I follow this sometimes but having a wide range of patterns in the same project feels so dirty in a way... Although it makes sense, refactor only when you need to.

I understand. I feel like the consideration to make is: will the benefits of hooks outweigh the benefits of mixing different patterns? If your estimate is that it won't, I'd stick to the current patterns for a while, rather than rewriting them now - because I'm quite sure the benefits of hooks aren't going to be worth the rewrite.

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

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

This post by React dev lead Dan Abramov goes deep into this question (much more detail than is available in the React Hooks FAQ or the ReactConf talks). https://overreacted.io/why-do-hooks-rely-on-call-order/ tl;dr: The primary design goal of hooks is to support the creation of custom hooks, which can eliminate the need for higher-order components in many cases. An ideal alternative implementation would support custo…

I’m not a dev lead — if anyone, Sebastian (sebmarkbage) is.

I just enjoy turning his sentences into blog posts. :-)

Post reply on HN