Live data from Hacker News

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

reactjs.org

161–170 of 181 posts

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

#161

Earlier quoted context omitted.

> Glad to read that as the top comment, because when they came out, I expressed strong doubts about this new features, and I mostly received mad comments in return. The alienated react fans stated that I didn't understand what modern code was, what a great idea those were and how from now on, everything will be better. Your post boils down to "Seems like it might be nice, but there might be bad sides, too" which seem…

No my answer boils down to: - hooks are technically interesting, but make it easy for humans to screw up. It's a precise critic. - the JS community has bad habits that can catalyse this, and above all, may lead them to avoid seing what's wrong - they get angry when we say it, and dismiss it as nonsense. Case in point.

The behavior that you see from a system is the behavior that that system encourages. I guess the proof will be in the pudding as to what hooks actually encourage.

I find a healthy dose of 'gloating dismissive' skepticism is usually a good thing. Because it stands in stark contrast 'gloating dismissive' dismissals of criticisms as 'nonsense' that usually come in the form "nah you just don't get it".

UI paradigms in particular warrant a good deal of skepticism in general. Every time it's "this is way!!!" and there are a whole slew of issues people regret wading into eventually down the line. Then new stuff comes out to fix those issues and "THIS is the way!!!" with the assumption that the new way doesn't have it's own problems (or at least the optimism is just ignoring them as they aren't salient enough yet to impact thinking). This just keeps playing out over and over. No reason its different this time.

So, I think it's absolutely fair to say "I wonder what nastiness come along with hooks that we are accepting as a trade-off for the potential benefits of Hooks?". At the same you can't compute the actual result as an intellectual exercise, so a healthy degree of optimism is warranted too in which we also ought to say "I'm excited to see if this really is the way and maybe we wont arrive at front-end utopia just yet, but hopefully we will get one step closer through the learnings".

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

#162
post #134
post #106

Earlier quoted context omitted.

There's nothing wrong with `setState`, in my opinion. However, it does do magic. Although it might feel like it immediately sets the state to be what you provide it as argument, it actually schedules a state update to be performed later when React feels like it. That's why it's best practice to provide an updated function rather than a plain object: if the new state depends on the previous one, and you read the previ…

I think the more relevant analogy between hooks and setState is that setState uses essentially the exact same technique as hooks to keep track of which component is calling it, namely, React keeps track of which component it’s rendering, and setState mutates some “global” state. A lot of people seem to think that setState stores state in the instance of the React component class, but that’s not the case (and that wou…

> setState mutates some “global” state

Is this true? Maybe I'm reading it wrong but this.setState in a React.Component just transparently calls out to `this.updater`[1] where `this.updater` is injected by the particular platform library (eg react-dom). At least in react-dom/server's case, a unique `updater` object exists per-component[2], so it's effectively a private instance field; and those state changes apply to a similarly per-component `inst.state`[3]

You can also prove this by calling setState with the wrong `this`: `this.setState.call({}, {x:1})` blows up. So the `this` is required, unlike how `useState` works.

[1]: https://github.com/facebook/react/blob/aa9423701e99a194d65a8... [2]: https://github.com/facebook/react/blob/aa9423701e99a194d65a8... [3]: https://github.com/facebook/react/blob/aa9423701e99a194d65a8...

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

#163

Earlier quoted context omitted.

Do you find it concerning that many software engineers with extensive professional React experience have such a difficult time understanding hooks?

Personally, I don't find it any more concerning that many software engineers with extensive professional web development experience had such a difficult time understanding React when it came out. (It was universally ridiculed and dismissed for about a year after it came out.) It's a different mental model. It doesn't "click" immediately for everyone but I've seen it "click" enough times for both beginners and experie…

I don't really remember there being much of a misunderstanding of React itself when it was first launched. There was definitely ridicule ("markup and logic in the same file?!"), but the general idea behind the core of it is pretty straightforward. I could be misremembering, it has been several years after all.

And I'm optimistic that hooks will be great and they won't be difficult to teach to React newcomers and more junior team members. But it's not obvious to me yet that it's the case and I'll be careful about how I use the feature going forward

Thanks for all your contributions to the community, though. Not trying to be overly critical of all the hard work — just trying to fully understand use cases, maintainability implications, etc.

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

#164

Do hooks work well with TypeScript? e.g. types will catch errors for you and you don't need to use "any"

Sure, the "magic" bit of hooks that people are talking about doesn't really affect their type signature

See eg, setState: `function useState(initialState: S | (() => S)): [S, Dispatch>];`

from: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/ab08...

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

#165

Earlier quoted context omitted.

> Glad to read that as the top comment, because when they came out, I expressed strong doubts about this new features, and I mostly received mad comments in return. The alienated react fans stated that I didn't understand what modern code was, what a great idea those were and how from now on, everything will be better. Your post boils down to "Seems like it might be nice, but there might be bad sides, too" which seem…

No my answer boils down to: - hooks are technically interesting, but make it easy for humans to screw up. It's a precise critic. - the JS community has bad habits that can catalyse this, and above all, may lead them to avoid seing what's wrong - they get angry when we say it, and dismiss it as nonsense. Case in point.

`hooks are technically interesting, but make it easy for humans to screw up. It's a precise critic.`

You just haven't tried it, right? I love when people talking big but in fact they have 0 exp on some topic.

As one who has adopted hooks in production for 2 projects, one is med-big size.

You CAN NOT screw up. Because if you did, it even won't work or won't build.

And how it helps to decouple logic and code sharing is fantastic.

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

#166
post #124

Earlier quoted context omitted.

> Hooks offers nothing new over HoC and FaC You've missed the point entirely. Hooks offer nothing new because their functionality was already implemented in React class components. They literally add no functionality to React. The docs actually state quite clearly that developers are discouraged from replacing class components with function components.

And what do you think React can do that jQuery cannot? Heck, what do you think React can do that standard HTML5/JS API cannot do? React doesn't offer new functionality to do UI. It offer new ways to think about the problem. Hooks doesn't offer any new functionality over `this.state` and component life cycle, it offser new way to think about the problem.

> And what do you think React can do that jQuery cannot?

Again, you've missed the point.

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

#168

Earlier quoted context omitted.

The syntax isn't even that weird? It's just function calls. The only "weird" bit is using array destructuring for multi-return and that's been in ES/JS for some time now, and definitely shouldn't look that weird to anyone that has worked in Python, as one example (and C# now supports destructuring even).

The weirdness is because the state or context seemingly comes from thin air - there's no explicit location for the data.

That's not really a syntax problem, though.

Also, hidden state/context is also not that weird? Do you need to know the exact location of the memory/stream that `console.log()` writes to in order to log the console? The physical details of how `navigator.compass.getHeading()` gets its information to use a compass heading? Both of those trampoline off into native code and the details of what the actual "explicit" locations for them is both irrelevant and highly variable depending on browser and system.

Unless you are looking at the namespace "objects" such as `console` or `navigator.compass` as "explicit locations", but you can add namespaces to your imports if that helps you feel like things are more "grounded". Import it and use it as `React.useState()` instead, for instance.

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

#169

Earlier quoted context omitted.

No my answer boils down to: - hooks are technically interesting, but make it easy for humans to screw up. It's a precise critic. - the JS community has bad habits that can catalyse this, and above all, may lead them to avoid seing what's wrong - they get angry when we say it, and dismiss it as nonsense. Case in point.

`hooks are technically interesting, but make it easy for humans to screw up. It's a precise critic.` You just haven't tried it, right? I love when people talking big but in fact they have 0 exp on some topic. As one who has adopted hooks in production for 2 projects, one is med-big size. You CAN NOT screw up. Because if you did, it even won't work or won't build. And how it helps to decouple logic and code sharing is…

I don't expect bugs as a screw up, i expect technical debt.

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

#170

Earlier quoted context omitted.

The weirdness is because the state or context seemingly comes from thin air - there's no explicit location for the data.

That's not really a syntax problem, though. Also, hidden state/context is also not that weird? Do you need to know the exact location of the memory/stream that `console.log()` writes to in order to log the console? The physical details of how `navigator.compass.getHeading()` gets its information to use a compass heading? Both of those trampoline off into native code and the details of what the actual "explicit" locat…

Alright, weird semantics then.

The hooks calls are unusual compared to normal Javascript code. If you read the other comments on this thread you'll see that I'm not the only one saying that. It comes down to the fact that it's a call, inside a render function, that has different behaviour on each call to said parent function. It's very magical - and the React team admit that, so I'm not sure what exactly you are arguing against.

It's not like I'm new to Javascript either - I've been coding in JS for over 10 years. I understand how it works, but it's still weird-looking code. You can hack up the language to make stuff like the new hooks library, even without the unique quirks of React's internals. But libraries that intentionally do that to generate magical effects are generally considered "weird" too.

Post reply on HN