Hacker News new | ask | show | jobs
by the_gipsy 439 days ago
I've never seen a Teact project where UI = f(state). There is always heavy reliance on the "lifecycle" of components. So you compose "functions", but every function is using some global state, shared or not, it's meaningless to describe it as "functions".

The one project I've used that had redux was also a complete nightmare to work with, and hooks are the blessed way now apparently.

2 comments

The problem is most react developers are using the library because they want a job and see companies are using it, not because they believe in or even understand functional programming

The amount of times I've heard that classes = OOP and functions = functional is ridiculous

It doesn't have to be this way for most apps. One reason I've seen why people heavily rely on the lifecycle methods is that UI = f(state) isn't fast enough. But in more powerful languages like ClojureScript, you can keep track of which part of the state is accessed, and subsequently rerun only parts of the f that needs to rerun. As I understand, there is something called React compiler (https://github.com/facebook/react/tree/main/compiler) that tries to do this. But in a better language, this doesn't need to be a standalone tool, just a macro.
I agree, Elm also does UI=f(s) really nicely. But it's not something you can do in JavaScript while also keeping everything JavaScript.