News for hackers. Stuff that matters.
Re:Solid.js feels like what I always wanted React to be by sbergot on Tuesday March 01, 2022 @05:22AM (#30512271)
Yes hooks are not great. They violate too many functional programming rules that the react team pretend to care about.

I still like using them however. I had a few issues when trying to do more abstract code.

Re:Solid.js feels like what I always wanted React to be by jameshart on Tuesday March 01, 2022 @08:01AM (#30513563)
I don’t understand why people think react hooks are meant to be ‘functional’.

They are highly, deliberately, emphatically procedural.

The order they are called matters! The time of when they are called matters! The number of times they are called matters! You get a different result from calling the same hook with the same arguments at different times! You get different results if the call site for them is in different places!

They do enable you to do some things in JavaScript that are more easily enabled with higher ordered function stuff in functional languages, but there is nothing ‘functional’ about how hooks work or how they are used.

And that’s okay! ‘Functional’ doesn’t automatically mean ‘better’ and ‘procedural’ doesn’t mean ‘worse’. For what they do, hooks (considered as the entire hooks ecosystem including linting extensions that help enforce the rules as if they were syntax errors) are a very clever extension within JavaScript syntax that let you pull off some very neat separation of concerns in a reactive code model.

‘Functionalness’ has very little to do with whether hooks are good or bad.

Re:Solid.js feels like what I always wanted React to be by Izkata on Tuesday March 01, 2022 @10:25AM (#30515268)
> I don’t understand why people think react hooks are meant to be ‘functional’.

Because when function components first came along that's what the whole of React was supposed to be: "functional" UI, using things like redux or mobx for state. Plenty of guides still use that terminology even though React's homepage now uses "declarative".

That said I think they were always misusing the term, I remember this because I used to complain to people that react itself was declarative, not functional, and just gave the option of writing in a functional style.

Re:Solid.js feels like what I always wanted React to be by svachalek on Tuesday March 01, 2022 @12:43PM (#30517256)
I'm not sure what happened over there but they completely lost the plot with hooks. And now you're not "correct" or "modern" if you don't use them. They're ... fine, I guess. Most of the time. But not at all in line with the fairly clean and consistent vision of early React.