DEV Community

Discussion on: Managing state in Svelte

Collapse
 
fpassx profile image
Frédéric Passaniti

And what about the use case when we want to persist the state "remotely" (in opposition with locally)
Using a base64 hash in the URL (GET Param) to sync your local state with the url, and be able to bookmark and share a link and reload your app where you left it ?

Collapse
 
joshnuss profile image
Joshua Nussbaum

For remote state, you can always use fetch or websocket.

A useful approach is to create a store that is backed with a remote API. So whenever the store changes, you push the changes to the remote API and vice versa.

Here's an example of an HTTP REST store that manages a singleton:
gist.github.com/joshnuss/e4c4a4965...