Re:A Visual Guide to React Mental Models: UseState, UseEffec...
by pier25 on Friday May 29, 2020 @06:47PM
(#23356503)
I guess we're all different, but I've never had to think much about reactivity in Svelte.
Most of it can be explained in a HN comment:
Component state just does its thing. You change it with = and the component is re-rendered.
Writable stores need to trigger changes with set() and you need to use $ whenever you reference it in a .svelte file so that Svelte handles subscription automatically.
Reactive statements $: are a bit more complex. Every variable inside those is referenced by the compiler so that it knows when you are mutating it. Either with = or if it's a writable store with set().
Most of it can be explained in a HN comment:
Component state just does its thing. You change it with = and the component is re-rendered.
Writable stores need to trigger changes with set() and you need to use $ whenever you reference it in a .svelte file so that Svelte handles subscription automatically.
Reactive statements $: are a bit more complex. Every variable inside those is referenced by the compiler so that it knows when you are mutating it. Either with = or if it's a writable store with set().