Hacker News new | ask | show | jobs
by SJC_Hacker 30 days ago
React Components are actually a far cry from OOP

React is actually more functional than anything else.

Of course if you actually try to be pure functional many developers will scream at you “prop drilling! Code smell!” But to me that it is a much lesser evil than useContext() and what is essentially global variables

1 comments

An important trait of good functional code is use of persistent data structures. JS code using React is anything but that with state hidden across numerous tiny functional closures.

The only language/framework that is truly functional in that sense is Elm.

I say this as someone who has done their fair share of Haskell, this just isn't a problem in practice, unless you're inexperienced or working with no experienced people.

I get this isn't everyone, and not everyone has the luxury to work in settings where this is a nonissue, but in those settings it sounds like the technology is being used as a restraint jacket for dysfunctional organisation.

When its been a problem, its always because the organisation was dysfunctional, "design" and "engineering" was what people did post humorously to justify spending time on their hobby horse.

Like 99% of components I've written project props on into other components and interpret them in purely. I often manage application state in external stores, which are decoupled from the view.

I should have mentioned language/framework for JS. The thing with Elm is that it gives a straightforward way (even if verbose) to design the whole app around persistent data structures. That gives so many benefits especially long term (time-travelling debugging support, easy insights into app state, full coverage by unit tests etc.). On the other hand my experience with React is that the state hidden in all those functional hooks is hard to debug and reason about with completely unpredictable and non-intuitive behaviour. I think the switch from class components to hooks was a big mistake.