3

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 Answer 1

6

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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.