Why React is not Functional
mckoder.medium.com
mckoder.medium.com
https://www.reddit.com/r/javascript/comments/nnu7vf/why_reac...
The point of the FP concepts introduced to React is to lessen the cognitive load of the render cycle _of an individual component_. But I think the team is pretty clear about when side effects are part of patterning (literally one of the hooks is called “useEffect”).
“ All React components must act like pure functions with respect to their props.”
Which they do. You cannot and must not mutate props. There are of course ways around this (JavaScript being JavaScript) by, say, passing a useRef defined constant down and then updating its “current” field, but that’s completely on you.
How about this quote:
"Finally, if you’re a functional programming purist and feel uneasy about React relying on mutable state as an implementation detail, you might find it satisfactory that handling Hooks could be implemented in a pure way using algebraic effects (if JavaScript supported them)."
That sure sounds like they are saying even FP purists should feel comfortable using hooks.
See https://medium.com/@dan_abramov/making-sense-of-react-hooks-...
This really makes it sound like functional programming cannot accomplish much of value.
Can't do I/O? Can't do UI? Is functional programming just for computation then? How many people even work in software that only does pure computation anymore? What good is pure computation if you can't even write it to a terminal after, because "No I/O"
This seems silly. Surely functional programming must have a broader definition than this.