In svelte, how to `console.log('yes')` when a variable changed?
I asked in Twitter, the answer is:
Link to the thread: https://twitter.com/liyuanqiu/status/1149235193296773122
I have recently been playing with svelte and needed to call a function when a property changed.
In Vue you would do it with watch
, but I could not find an equivilent in Svelte.
In my project have done it like this:
let c = 0;
$: if (c) {
console.log("yes");
}
I am not 100% sure if this is the correct way or not though.
Hopefully Rich Harris will chime in here as I would like to know.