Live data from Hacker News

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

reactjs.org

61–70 of 181 posts

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

#61
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?

We’re not refactoring anything at FB and don’t recommend you to either!

We mostly use Hooks in new code.

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

#62
post #10

Earlier quoted context omitted.

I've been working with hooks for quite a while now; its main benefit is composability - before hooks up you rely on Higher order components (HOCs, HOFs but in component rendering) to provide composability of component behaviour - this is messy, very messy, and not performant. By using hooks the logic tidies up massively (so working on it becomes a lot quicker) and several hard to diagnose performance bottlenecks disa…

Can you please give some example of behaviour that you share across components that couldn't be factored out into a function?

I tried to explain it here.

https://medium.com/@dan_abramov/making-sense-of-react-hooks-...

Hope it helps!

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

#63
I am stealing this thread as it seems to have a lot of really knowledgable people in here.

I understand basic javascript but I am not an expert and I had a discussion with a developer I want to hire for a new app I am doing, who said that there is no open source components (like quill) which easily allow you to have textformating (bulleted lists, bold, text size etc) and that it would have to be done from scratch) which sounded weird to me since I found a quill component.

But I am not a developer so I need to educate myself a little better. What's a good tutorial to get my head around how React works.

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

#64

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 make a lot more sense from a traditional FRP perspective. The code you write with hooks is basically identical to the code you'd write with early FRP systems. For instance, useState is called newWire in FranTk. The difference is that hooks have various limitations about where you can create them and how you can pass them around, which those FRP systems don't have. That's the result of React using plain old data as state, instead of having a signal abstraction as in FRP. In React the component function gets re-executed every time the state changes, whereas with FRP the component function gets executed once and builds up a dataflow graph that deals with the changes. That makes hooks very natural because they're just nodes in the dataflow graph.

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

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

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

#66
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?

Why refactoring? It might be marginally better, but it doesnt mean what has been written in the past is wrong. Plus unless you have very robust test coverage, refractoring at this scale is going to introduce more bugs than the marginal benefits it will bring.

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

#67
post #38
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.

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 you have the same `this` then you have the same state.

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

#68
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 months at FB and haven’t seen confusion caused by the call order reliance.

(Note Hooks don’t rely on specific call order but just on it being static between renders. Which is pretty easy to understand and reasonably enforce in practice.)

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

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

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

#70
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?

We’re not refactoring anything at FB and don’t recommend you to either! We mostly use Hooks in new code.

Sounds good! Absolutely didn’t expect getting a reply from you on this :)

I’ll use them in a couple new features and see how nice and tidy I can make things look, then think about how we’ll continue going forward.

Still have a bunch of componentWillReceiveProps that need attention as well...!

Post reply on HN