-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path.cursrorrules
61 lines (54 loc) · 1.47 KB
/
.cursrorrules
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
New in SvelteKit 5:
# Runes
## Reactivity
Reactivity with
let x = "hello
at compontnt top-level is replaced with
let x = $state("hello")
This makes x reactive in the component, and also in any js functions that operate on it.
## Derived values
Only style:
$: b = a + 1
New style:
let b = $derived(a + 1)
Or for more comples cases use $derived.by():
let b = $derived.by( () => {
....
return a + 1;
})
## Effect
let a = $state(1);
let b = $state(2);
let c
$effect(() => { // This will run when the component is mounted, and for every updates to a and b.
c = a + b;
});
Note: This does not apply to values that are read asynchronously insude $effect, they are not tracked.
Note: Values inside the objects are not tracked inside $effect:
// this will run once, because `state` is never reassigned (only mutated)
$effect(() => {
state;
});
// this will run whenever `state.value` changes...
$effect(() => {
state.value;
});
An effect only depends on the values that it read the last time it ran.
$effect(() => {
if (a || b) { ...}
});
If a was true, b was not read, and the effect won't run when b changes.
## Props
Old way to pass props to a component:
export let a = "hello";
export let b;
New way:
let {a = "hello", b, ...everythingElse} = $props()
a and b are reactive.
To use types:
let {a = "hello", b}: {a: string, b: number} = $props()
Note: The preview syntax
let { x = 42 } = $props<{ x?: string }>();
no longer works.
## Event changes
Use onclick={...} instead of on:click={...}