4 ms·
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
by sbergot 5y ago
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.
- jameshart 5y agoI 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.
- Izkata 5y ago> 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.
- svachalek 5y agoI'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.