|
|
|
|
|
by prewett
1064 days ago
|
|
Hooks are particularly bad to reason about. I can't figure out why hooks seems to be the official Way, it just leads to a bunch of spaghetti functions. The old object-oriented approach might feel old and creaky, but OOP was invented for user interface. Functional programming, not so much. |
|
Even eliminating/substituting one of those (underlying language) can go a long way towards making FP UI a nicer experience. For example, Reagent[1] in ClojureScript has a state management approach that’s conceptually similar to hooks, but it uses the language’s own reference type semantics in a way that makes it much less awkward. It’s still a challenge to integrate (JS) libraries with side effects, but the community does a pretty good job of wrapping the more popular ones in idiomatic functional APIs.
The concept that ui = function(state) is incredibly powerful if you can stay within the concept. It can have some performance downsides, but even those can benefit from a language/foundation designed for it (eg with Clojure[Script]’s persistent data structures).
1: https://reagent-project.github.io/