Svelte stores are an important feature of the Svelte framework that enables the sharing of state between components. In this tutorial, we will learn how to use Svelte stores.
Before we begin, let's define what a store is in Svelte. A store is an object that holds a piece of reactive state. When the state in the store changes, any component that has subscribed to the store will be automatically updated.
There are two types of stores in Svelte:
readable stores. A writable store allows you to update the value of the store, while a readable store only allows you to read the value of the store.
Now, let's dive into the steps for using Svelte stores:
Import the stores module
The first step is to import the stores module from Svelte.