The point of Svelte stores

Why

In single-page applications, different pages are constructed using components. Often you need to share some data across them. Also, after the initial server render further interactions happen on the client-side, so, you need some way to store the initial state you got from the server.

What

Many frameworks have their respective recommended way of managing the state. Angular has Rxjs, React with Redux, and Svelte has Svelte-stores

How

Instead of how these state libraries work internally, let’s look at how these are used in an app, specifically Svelte.

Diagram

An image always makes more sense before we look at the code 

Code

Working Sample Code hosted online at REPL

App.svelte

Login.svelte

Dashboard.svelte

store.js

Now, go fix some bugs!

Leave a comment