5 ms·
I never got the appeal of state management in React. People now seem to rave about Svelte, because you can just do 'count += 1'. But you could do exactly this a
by kabes 6y ago
I never got the appeal of state management in React. People now seem to rave about Svelte, because you can just do 'count += 1'.
But you could do exactly this already in Angularjs (which, just like Svelte, had a template language).
Ok, Angularjs worked different under-the-hood than Svelte. It was a dirty checking loop instead of compiler-generated change indicators, which didn't scale as well. But other than this scaling issue, the ergonomics were very similar.
But in the meanwhile the React folks started this whole idea that this mutable state was a bad idea and people seemed to blindly believe the React way was going to be the silver bullet. The widely acclaimed Dan Abramov launched Redux, one of the most cumbersome, boiler-plate-heavy state management systems I've ever had the displeasure of using. And with react hooks there are more performance pitfalls than there ever were with Angularjs.
So now everyone seems to realize that they lost quite some convenience with React. React had a good run, but it's time to move on.
- padolsey 6y agoWhat perf issue have you spotted with hooks? My biggest bugbear with them is just the sheer cognitive exhaustion that comes with figuring out "when" stuff is happening -- especially if you're implementing a bunch of your own useEffects. I remember just sitting there bemused by the complexity -- and the difficulty of debugging ostensibly simple state changes. I (truly!) miss the good old days of intuitely doing count+=1 in a mess of procedural DHTML... so for that reason alone Svelte is a breath of fresh air.
- kabes 6y agoFor example passing down a function which is not memoized can trigger a bunch of non-obvious side effects lower in the component tree when your component re-renders. I feel like with hooks/functional components I need to think way more about stuff like that. Which comes down to your point: cognitive exhaustion. The promise of hooks and functional components was that it would make things 'easier to reason about' (among other things). But we all know now that this is just not the case in practice.
- j-krieger 6y agoIt's because react works with immutable state. Svelte instead opts for compile-time magicks to handle state. Angular uses decorators to manage state. This has turned out to be an unwise descision because javascript decorators have changed in spec since then.
- kabes 6y agoI was talking about angularjs. not angular. And like I said, react promised immutable state would solve a lot of problems, but it turns out you lose a lot of convenience as a developer while not gaining that much.
- WouterSpaak 6y agoAngular does not use decorators to manage state. It uses decorators to create compile-time instructions for the dependency injection system to wire components, services, and directives together (I'm simplifying a bit here). Should TypeScript ever drop their decorator implementation, this could all be fairly easily changed to do it with functions instead: export class AppComponent { } export const appComponent = Component(AppComponent, { template: '<h1>Hello World!>/h1> // other compile-time instructions }); How you want to approach runtime state has nothing to do with decorators.