DEV Community

Zen
Zen

Posted on

Store in Svelte

store.js

import {writable} from "svelte/store"
export const apple = writable(5)
Enter fullscreen mode Exit fullscreen mode

Get store

<p>I have {$apple} apples</p>
<script>
 import {apple} from "./store.js"
</script>
Enter fullscreen mode Exit fullscreen mode

Change store

import {apple} from "./store.js"
$apple = 10
Enter fullscreen mode Exit fullscreen mode

or

import {apple} from "./store.js"
$apple = $apple + 1
Enter fullscreen mode Exit fullscreen mode

Top comments (0)