Svelte Store

Svelte Store is a state management solution provided by the Svelte framework. It is designed to help manage and share state across different components in a Svelte application. Svelte Store follows the principles of reactive programming, allowing components to automatically update when the underlying state changes.

Store Functions :

set
update

Sample Code :

Create store.js inside `src` folder

import { writable } from 'svelte/store';

export const count = writable(0);

Set : 0

Set the Value using .set()

Go to +page.svelte

import { count } from "./store.js";

count.set(10);

Update: 0

Set the Value using .update()

Go to +page.svelte

import { count } from "./store.js";

count.update(n=>n+10);

Update is used to change the value of Store ....it will affect at global level wherever the store is used.