Chapter 4: Stores
Svelte’s reactivity inside Svelte components is intuitive and easy. Because Svelte is a compiler, it can transform regular variable assignments into something the UI will rerender when it changes (as we saw in Chapter 2). Reactive assignments make derived or computed variables very easy (as we saw in Chapter3).
Outside of Svelte components, we have a different mental model, there’s no inherently connected UI layer to our code, and the Svelte compiler won’t touch code outside of Svelte files. But what if we also want the goodies of reactivity outside of Svelte components? What if we have global state that lives inside a JavaScript file that many components should react to when it changes? This is where Svelte stores come in. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access