RedditPP Mascot

RedditPP

r/sveltejs • … • u/Rocket_Scientist2

Does Svelte 5 derived/effect reactivity still feel like *magic*?

I've been using Svelte 5 a little bit, and something has broken my brain a little bit. When I think of derived reactivity in Svelte 4:

let a = 5; $: b = a * 2;

This doesn't bother me for some reason (no closure maybe?). When I think of stores, this makes more sense.

let a = writable(5); let b; a.subscribe((v) => b = v * 2);

—or something like that, you get the idea. You're passing a function to be re-evaluated.

In Svelte 5, you don't get the same treatment. For example:

let a = $state(5); let b = $derived(a * 2);

In my few days' experience, I find this feels off, and I keep wanting to pass a function to the runes, e.g.

let b = $derived(() => a * 2);

To me, it feels a little unnatural for a static declaration to be re-evaluated without wrapping it in a function. I'm not voicing my opinions to/against these changes, I'm just curious if anyone has felt something similar or not. Post your experiences in the comments.

— 0