$state the new store ? #10262
Replies: 5 comments 4 replies
|
+1 this question. I'm considering open-sourcing our store helper library, but if stores won't be a large part of svelte 5 I'd rather wait for runes to stabilize before releasing anything. |
|
I have done some playing around with state in a try out app, and so far it seems like $state can be used like stores, but with the additional benefits of not needing special syntax/methods (can be used just like any object) and fine-grained nested reactivity - I'm even starting to wonder if a whole app can be driven by a single $state. |
|
I don't see stores going anywhere as
For However, I haven't really played with Svelte 5, so maybe all of this is actually possible with |
|
For shared state across components: <!-- state.svelte.js -->
export const count = $state(0); // exportable, shared across importersThis is the runes-era equivalent of a store. Unlike a writable store, it doesn't need For local component state: <script>
let count = $state(0); // local to this component
</script>The conceptual shift: The migration path: if you have What's the specific use case you're trying to figure out the right pattern for? |
|
I feel the tail of this thread shouldn't end on misinformation, which could cost any reader time if they tried to directly export state. So I'm just going to leave this link to the docs: https://svelte.dev/docs/svelte/$state#Passing-state-across-modules |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I was under the impression that $state are meant to replace stores. Yet, if they can't be used in normal js/ts files (e.g. to run unit tests), their usability seems quite limited. I think a comparison table would be helpful when to use a store vs state.
Also, will stores also gain deep fine-grained reactivity in svelte 5 ?
I guess $state is a compiler level feature, but I'm wondering if it would be truly impossible to make it importable so it can be used in any js files, rendering stores obsolete while allowing for straightforward use with TDD.
All reactions