News for hackers. Stuff that matters.
Re:SvelteKit 1.0 by unsupp0rted on Wednesday December 14, 2022 @01:13PM (#33987359)
I had the opposite feeling a month or so ago, especially with stores- there's so much "magic" that I kept running into confusing walls.

If I `export let` a variable to be reactive over here, why isn't it reactive over there?

Re:SvelteKit 1.0 by samtp on Wednesday December 14, 2022 @01:41PM (#33987916)
You seem to be conflating a few different concepts. Store are absolutely reactive across all components and pages. They are prefaced with $, and there are a bunch of native stores that you can use such as $page.

You can even create variables reactive to one another by declaring a variable like so:

$: y = x * 2

Using the export let x = default; option is for passing data from the parent component/page to a child. If you want variable changes in the child to be reflected in the parent, you can use a store ($ notation), or you can use bind like so:

<ChildComponent bind:x={someValue}>

In my opinion, all of this is much much easier than in competing frameworks.

Re:SvelteKit 1.0 by unsupp0rted on Wednesday December 14, 2022 @03:42PM (#33990235)
For instance I had a variable in a store.

On my page, I had a script tag pulling from the store. The variable was reactive within the script tag.

I export let that into the template via “data” props.

I changed the value of the variable within the script tag.

The template did not reflect the new value.

Re:SvelteKit 1.0 by samtp on Wednesday December 14, 2022 @04:50PM (#33991105)
I'm really struggling to follow what you're trying to do - but why do you not just use the same writable store in both your page and template/component?

Also, maybe look into store subscriptions and/or reactive declarations for what you're trying to do.

Regardless, it sounds like you really need to just read the docs or do a tutorial.