Get/Read Value From Svelte Store

Viewed 884

I want to read svelte store value at any given time. I understand subscribe method gets called when the value is updated. I want to read store even if there is no update on store.

1 Answers

Just like any other variable, you can use it in your template(markup) with $ in front of the store variable it is as simple as that!

App.svelte

<script>
    import { count } from './stores.js';
</script>

<h1>
    {$count}
</h1>

stores.js

import { writable } from 'svelte/store';

export const count = writable(0);
Related