7 ms·
I like Svelte more than React (it's store management)
- rendall 1y agoSmall critique: you probably want its (possessive of "it") in the title rather than it's ("it is") as in: > I like Svelte more than React (its store management)
- deleted 1y ago[deleted]
- bravesoul2 1y agoCorrect: when it's possessive, its form of it is its not it's. Easy mnemomic: the apostrophe is for a missing letter, I.
- okonomiyaki3000 1y agoAlso `a lot` not `alot`
- bsaul 1y agoas a non english native, i find it incredible how many native english speakers do this mistake
- zamadatix 1y agoIf enough of us make this mistake then maybe the prescriptive half can drop the whole "possessive pronouns don't get an apostrophe" rule altogether :D. The same goes for "alot", avoiding the use of "whom", and so on - I ain't gonna give up on them!
- deleted 1y ago[deleted]
- elpocko 1y agoI think they've given up on this, it's ubiquitous. I've recently noticed that a CLIP model (a neural network for image understanding) gave me image descriptions using "it's" where "its" would have been correct. Hundreds of thousands of dollars to train the thing; no one noticed, no one cared ¯\_(ツ)_/¯
- billforsternz 1y agoIronic that this is one case when you don't use an apostrophe to indicate the possessing entity. I suppose the rule is possessive nouns only, not pronouns.
- tln 1y agoWith the original title, it's perfect, but after the edits its coherence is a little fractured... Honestly I don't love HN's title edits. Why can't we have nice blog titles that start with why?
- davedx 1y agoThe problems with these examples in my opinion is they often extend extremely trivial examples of problems to large, complex applications with a lot of assumptions about the problems those large, complex applications are likely to have. It's great that there are alternatives to React, and that they do some things better than it. But what I find is that most large, complex applications I've worked on are not in particular hindered by the choice of React as a technology. It does vary from project to project too, of course - some applications will benefit more from some kind of well designed central state management solution.
- skydhash 1y ago> But what I find is that most large, complex applications I've worked on are not in particular hindered by the choice of React as a technology. AKA, React is accidental complexity. Solving accidental complexity issues may be required some time, but more often than not, it's just something you endure as the alternative choices are not that much better.
- owebmaster 1y agoWhy are the alternatives not better if, as you say (and I agree), react solves its own problems (accidental complexity)? not some essential complexity (at least not anymore). State management and optimized DOM manipulation can be achieved with vanillajs nowadays and I'm not saying that as a purist, it is just good enough that React is not needed. To help a bit with the ergonomics, I use lit-html/uhtml for the templating but they are both based on template literals, a native JS feature.
- skydhash 1y ago> Why are the alternatives not better if, as you say (and I agree), react solves its own problems (accidental complexity)? not some essential complexity (at least not anymore). The essential complexity was the interactive need of your UI. Any of the current web framework can be a solution. The only reason to go for React is hireability (almost anyone knows it) and devex (so many prebuilt components). But it's not like that the others are so hard to learn and components are hard to build.
- fabioz 1y agoIsn't `useContext` the builtin React alternative to that issue?
- Already__Taken 1y agoYes but they will rerender from where the context was created not where it's used, so you can get a lot of UI renders. I think the new memo compiler address' this in the most complicated way possible.
- owebmaster 1y ago> Yes but they will rerender from where the context was created Wow that's really bad and make it basically useless.
- jgalt212 1y agonot if the compiler stops the unneeded re-renders.
- owebmaster 1y agoA "compiler" to solve the issues the library created, awesome. It doesn't solve many re-renders tho, as React re-render full components, not only the HTML/Text Nodes that changed.
- Capricorn2481 1y agoA re-render in React is not as heavy as you'd think it is. It's painting the DOM that takes resources, and people conflate the two. But if your whole component re-renders because of a change in context, yet nothing on the page changed, you will likely not notice the render even on low-end devices. I still think Zustand is the simplest state management, while staying efficient. It's similar to the old Svelte stores. But I have used many state management tools and the re-renders were not the problem when it came to speed.
- SebastianKra 1y ago
- piracyrules 1y ago[flagged]
- 0xfffafaCrash 1y agoReact doesn’t really concern itself with state management. Of course it has context, state, and props but the mental model for it predates focus on fine grained reactivity in frontends — useSyncExternalStore helps enable others to fill that void in v17+. Fine grained reactivity was notably also missed in the development of web components — only now is there a tc39 proposal for signals (in its early stages). Jotai, mentioned briefly in the article, may not be built in but is as intuitive as signals get and isn’t even tied to React as of later versions. I’ve very rarely met a state management problem in clientside state management where neither tanstack query (for io related state) nor jotai (for everything else) are the best answer technically speaking. The rare exceptions are usually best served by xstate if you want to model things with FSMs or with zustand if you actually need a reducer pattern. There’s a tiny niche where redux makes sense (you want to log all state transitions or use rewind or are heavily leaning on its devtools) but it was the first to get popular and retains relevance due to the fact that everyone has used it. You can go a long way with useContext and useReducer/useState but few would opt for alternatives if jotai came batteries included with react.
- Stoids 1y agoMost UIs I've written in my career benefit from being modeled as FSMs. While I see the value proposition of the atom-based approaches, especially for basic applications, I can't help but become a bit hesitant about their scalability long-term on large teams. Part of the reason the very dogmatic Redux approach of a event dispatching + single store of truth caught on so quickly was because a lot of us had felt the pain of two-way data binding / global state with event listeners in Angular 1. I distinctly remember the horror of debugging digest loops (scope.$$phase memories) and being completely lost in the unstructured data flow. What made for a great demo became a nightmare at scale. There's nothing stopping people from using these atom-based libraries to build more robust abstractions, but from my professional experience I tend to just see global getters and setters with useEffects / lifecycle method of your frameworks choice as a side effect sync. Maybe my instincts are off here though and I am overly cautious. I love XState but the learning curve is rather massive and getting buy in from other team members is hard when the DX of the atom approach is so nice. I feel like state "management" and reactivity performance are talked about a lot, when ultimately state orchestration is where I see things fall over the most.
- 90s_dev 1y agoAccording to a resonating reddit comment, Svelte isn't more popular because it's simply too late; React and Vue got there early and got good enough, so Svelte can't really get as big as them. I think this might be true short term, but long term it means Svelte has more room to evolve with the web and with JavaScript itself, since fewer users means more room to move fast and break things, like Zig can and does. And Zig isn't dead. This gives me a little encouragement for my personal web reactivity project. I'm confident I came up with a reactivity model that's technically innovative, which does and is what I always wanted React to do and be. But being so late to the game, my hypothetical framework has no chance to gain traction. I say hypothetical because I haven't even started making it yet. It would be built on the Ref class[1] that came out of my experimental work on os.90s.dev, but only last night did I finally get around to experimenting with using it with HTML[2]. The concept is to have JSX transform to allowing attributes to be given MaybeRefs and if its a ref then watch it and set the attr to the value, and just return the HTMLElement itself. This should be a good enough foundation to build an entire reactive framework around. Having almost no users is a blessing, because it gives me the complete freedom to experiment with this relatively slowly. The time between creating refs and stabilizing them was a few months. The time between stabilizing them and using them in that experiment was another month. It'll probably be another month before I get a functioning non-trivial app working with it. And another few months before it's cleaned up enough to be both generic and convenient. Maybe this should have been a blog post. I never know. [1]: https://90s.dev/guides/refs.html https://90s.dev/guides/refs.html [2]: https://github.com/sdegutis/bubbles/commit/cde2bea973b22538f332fa169de8623755731b4f https://github.com/sdegutis/bubbles/commit/cde2bea973b22538f...
- ricardobeat 1y ago> The concept is to have JSX transform to allowing attributes to be given MaybeRefs, and if its a ref then watch it and set the attr to the value That is essentially what Signals are, including directly setting .textContent when possible. This model actually predates all of this and was used way back, in Backbone.js and other pre-react frameworks, except we didn’t have JSX or virtual DOM at the time.
- 1y ago
- CharlieDigital 1y agoMan people are really missing out on Vue and Pinia. Pinia is so low ceremony and "just works"; it makes state management concerns practically disappear.
- alabhyajindal 1y agoI had never heard of Pinia. Visited their landing page [1] and there's a button selling a course on how to use the library. There's a CTA for the course when you go to the Guide page as well. Very strange! 1. https://pinia.vuejs.org https://pinia.vuejs.org
- aitchnyu 1y agoIn 2018, I taught Vue workshops where I memorized a Vue enabled html page and went through links from the homepage. Since then, Vue took permutations of options/composition, js/ts, Vite/whatever and deferred documentation to Vue teaching sponsors.
- CharlieDigital 1y agoTry it. No course needed. Whatever you learn in the first hour scales to the 100th hour. That's the best kind of simple.
- ezarowny 1y agoIf you're writing Svelte code today and you need shared state, I would recommend you start by looking at the Context API (https://svelte.dev/docs/svelte/context https://svelte.dev/docs/svelte/context). For manual control of data updates you'll probably still want to use Stores (SvelteKit does!) but I'd start with Context first.
- mhh__ 1y agoI also like svelte quite a lot although I was/am genuinely a bit confused as to how to join svelte to some external [state machine / business logic]. I ended up with runes basically infecting the entire codebase, but presumably a proper boundary must be possible?
- tonyhart7 1y agoYeah, I try build an dashboard admin that has complex state passing into each other and its not elegant, lets call it that way
- Leftium 1y agoFor complex things, I came up with a pattern that stores the state externally from the components in a single centralized file. So the components just become simple shells that render the state and forward events. (All the complex business logic can be tested without the DOM/headless browser.) I call it "nation state" because it groups sets of related variables together in a scope between local and global. I implemented the pattern with Svelte runes, but I think it could be implemented with anything; even React. I went into more detail here (with live example/code): https://www.reddit.com/r/sveltejs/comments/1dgf8la/comment/l8rxo2d/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1 https://www.reddit.com/r/sveltejs/comments/1dgf8la/comment/l...
- jmogly 1y agoYes this is the way to do it, global-ish state files with getters and setters. I’ll have a .svelte.ts file (or a few of them) with a typed state object, maybe a function for refreshing it or syncing it with a backend api, import the state all over the place. Might be an anti pattern but it works really well.
- mhh__ 1y agoI think I follow but IIRC my problem was something like that the getters and setters had to be quite "flat". if they weren't they would recursively infect everything top-down and then not work anyway because of boundaries in the deep reactivity.
- vtemp99 1y ago[dead]
- defraudbah 1y agothe end example is the same as zustand, no? svelte has earned it's place and the more people use it - the better. I couldn't find a reason to switch, same with ember in early days, same with any handlebars go/php/rust etc. We live in the era when it's enough to learn one UI framework and just ship things. Good post though, I wish it had more examples so
- fny 1y agoMy only gripe with Svelte is that it’s not JavaScript. There’s an arcane layer of $yntax to mediate and a lot of flexibility and intuition is lost as a result.
- FpUser 1y agoFor generic browser based application I am in favor and am using domain specific libraries like three.js and purposely made web components. For the rest modern javascript works just fine. I just do not see the value of those framework monstrosities and build processes. They might be solving some problems for companies of Meta's scale but on small dedicated teams in my opinion it is just waste of time and money for no tangible benefits.
- EmilienCosson 1y agoI think it is useful to say the blog post is using svelte 4, and the svelte 5 docs mention: “When to use stores Prior to Svelte 5, stores were the go-to solution for creating cross-component reactive states or extracting logic. With runes, these use cases have greatly diminished. when extracting logic, it’s better to take advantage of runes’ universal reactivity: You can use runes outside the top level of components and even place them into JavaScript or TypeScript files (using a .svelte.js or .svelte.ts file ending) when creating shared state, you can create a $state object containing the values you need and then manipulate said state state.svelte export const userState = $state({ name: 'name', /* ... */ }); App <script lang="ts"> import { userState } from './state.svelte.js'; </script> <p>User name: {userState.name}</p> <button onclick={() => { userState.name = 'new name'; }}> change name </button> Stores are still a good solution when you have complex asynchronous data streams or it’s important to have more manual control over updating values or listening to changes. If you’re familiar with RxJs and want to reuse that knowledge, the $ also comes in handy for you.” https://svelte.dev/docs/svelte/stores#When-to-use-stores https://svelte.dev/docs/svelte/stores#When-to-use-stores
- philipwhiuk 1y agoSvelte stores just sound like adding Redux to React, which used to be in vogue then stopped being in vogue and I guess this blog post marks them being back in vogue.
- digianarchist 1y agoThe blog post compares an example using hooks to pass in a state and update function to a child component. It then compares that to a Svelte component which contains a state variable. Those two examples aren't equivalent because any parent component wrapping the Svelte component doesn't have access to the state whilst App (in the React example) does. For the Svelte example to be equivalent, the component would have to export the store. A minor gripe but the hooks vs Svelte state is pretty minor issue in itself.
- SebastianKra 1y agoThere's an issue when integrating Signals (or Stores) directly into templates. TypeScript becomes unable to track how bindings relate to each other. This is described in the Solid documentation: https://docs.solidjs.com/configuration/typescript#control-flow-based-narrowing https://docs.solidjs.com/configuration/typescript#control-fl... In my experience with data-binding, these instances of disabling the typesystem accumulated, and became a frequent source of bugs. So even though I hope for Signals to catch on, I believe the best way of connection to them will still be React: function Output({ userSignal }) { const user = useSignal(userSignal) if (!user) return <span>No user found</span> return <span>{user.firstName} {user.lastName}</span> /* TypeScript knows that user must be defined */ }