|
|
|
|
|
by ExtremisAndy
1109 days ago
|
|
I wanted to like React so bad. I tried. I loved JSX and really appreciated the way you could reuse components. That was all very cool, and I was initially quite enthusiastic about it. But for whatever reason, I just could not figure out state management/hooks. Drove me crazy. It just always felt so unnecessarily complicated compared to other languages and frameworks I've used (even vanilla JS). Now, don't get me wrong: I fully accept the blame here. I am mostly self-taught (and not even the best 'student' in that context, haha) so I'm sure I just lack the overall knowledge base/big-picture understanding to really appreciate what they've done here. I hope I'll give it another shot one day, and perhaps with fresh eyes (and maybe with the help of a patient tutor), it will all 'click'! |
|
I'll draw an analogy.
---
Why did async/await replace callbacks? They are really the same thing, aren't they? Aren't callbacks good enough?
Async/await allowed programmers to write asynchronous code as if it were synchronous.
---
Why did hooks replace classes/imperative? They are really the same thing, aren't they? Aren't classes/imperative good enough?
Hooks allowed programmers to write stateful code as if it were stateless.
This is functional code, without scary, hard-to-reason side-effects. Except for one limited part, which operates in a stateful way.I argue that this is simpler than the equivalent imperative-DOM modification code, and the gap between these only increases with real programs.
This isn't just a weird "web bro" thing; the hooks paradigm is useful (in theory and practice) to every UI platform.
I even wrote an implementation (closed source) for hooks in Angular. It was lovely.