DEV Community

Zen
Zen

Posted on

2 2

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)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay