DEV Community

loading...

Store in Svelte

mzaini30 profile image Zen ・1 min read

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

Discussion (0)

pic
Editor guide