Skip to content

Commit ab7481b

Browse files
Sync svelte docs (sveltejs#1100)
sync svelte docs Co-authored-by: Rich-Harris <[email protected]>
1 parent 66121df commit ab7481b

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

apps/svelte.dev/content/docs/svelte/02-runes/04-$effect.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,11 @@ An effect only reruns when the object it reads changes, not when a property insi
126126
<p>{state.value} doubled is {derived.value}</p>
127127
```
128128

129-
An effect only depends on the values that it read the last time it ran. If `a` is true, changes to `b` will [not cause this effect to rerun](/playground/untitled#H4sIAAAAAAAAE3WQ0WrDMAxFf0U1hTow1vcsMfQ7lj3YjlxEXTvEymC4_vfFC6Ewtidxde8RkrJw5DGJ9j2LoO8oWnGZJvEi-GuqIn2iZ1x1istsa6dLdqaJ1RAG9sigoYdjYs0onfYJm7fdMX85q3dE59CylA30CnJtDWxjSNHjq49XeZqXEChcT9usLUAOpIbHA0yzM78oColGhDVofLS3neZSS6mqOz-XD51ZmGOAGKwne-vztk-956CL0kAJsi7decupf4l658EUZX4I8yTWt93jSI5wFC3PC5aP8g0Aje5DcQEAAA==):
129+
An effect only depends on the values that it read the last time it ran. This has interesting implications for effects that have conditional code.
130+
131+
For instance, if `a` is `true` in the code snippet below, the code inside the `if` block will run and `b` will be evaluated. As such, changes to either `a` or `b` [will cause the effect to re-run](/playground/untitled#H4sIAAAAAAAAE3VQzWrDMAx-FdUU4kBp71li6EPstOxge0ox8-QQK2PD-N1nLy2F0Z2Evj9_chKkP1B04pnYscc3cRCT8xhF95IEf8-Vq0DBr8rzPB_jJ3qumNERH-E2ECNxiRF9tIubWY00lgcYNAywj6wZJS8rtk83wjwgCrXHaULLUrYwKEgVGrnkx-Dx6MNFNstK5OjSbFGbwE0gdXuT_zGYrjmAuco515Hr1p_uXak3K3MgCGS9s-9D2grU-judlQYXIencnzad-tdR79qZrMyvw9wd5Z8Yv1h09dz8mn8AkM7Pfo0BAAA=).
132+
133+
Conversely, if `a` is `false`, `b` will not be evaluated, and the effect will _only_ re-run when `a` changes.
130134

131135
```ts
132136
let a = false;
@@ -135,8 +139,8 @@ let b = false;
135139
$effect(() => {
136140
console.log('running');
137141

138-
if (a || b) {
139-
console.log('inside if block');
142+
if (a) {
143+
console.log('b:', b);
140144
}
141145
});
142146
```

0 commit comments

Comments
 (0)