Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why does Svelte not detect changes to my reactive data?

I am trying to update a variable on my page when it changes, but I am missing something on Svelte reactivity. Can someone please point out what is wrong?

REPL

App.svelte

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<main>
    <h1>Detect data</h1>
    <p>Board number: {$room_data.board_number}</p>
</main>

<script>
    import {room_data} from './stream.js'
</script>

stream.js

import { writable } from 'svelte/store'

export var room_data = writable({
    board_number: -1,
});

setTimeout(function() {
    room_data.board_number = 7;
    console.log('to');
}, 2000);

>Solution :

You are setting a property of the writable (not its contents) here:

room_data.board_number = 7;

You probably want to do:

room_data.set({ board_number: 7 });
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading