Quantcast
Channel: Active questions tagged svelte - Stack Overflow
Viewing all articles
Browse latest Browse all 1541

How to trigger a function when there is a value change in subscribed store in Svelte?

$
0
0

One of my components is subscribed to a variable in a store. Whenever there is a change in that store var, I want to trigger a function.

stores.js

    import { writable } from "svelte/store";     export const comparedProducts = writable([1,2,3]);

Component.svelte

    import { comparedProducts } from "../stores.js";    //if there is a change in $comparedProducts trigger this function eg. ([1,2])    const someFunction = () => {      //do something    }

Viewing all articles
Browse latest Browse all 1541

Trending Articles