Skip to content

Commit 120a062

Browse files
committed
update effect root example
1 parent 18f2426 commit 120a062

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

documentation/docs/02-runes/04-$effect.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -225,18 +225,19 @@ It is used to implement abstractions like [`createSubscriber`](/docs/svelte/svel
225225

226226
The `$effect.root` rune is an advanced feature that creates a non-tracked scope that doesn't auto-cleanup. This is useful for nested effects that you want to manually control. This rune also allows for the creation of effects outside of the component initialisation phase.
227227

228-
```svelte
229-
<script>
230-
const cleanup = $effect.root(() => {
231-
$effect(() => {
232-
// some effect
233-
});
234-
235-
return () => {
236-
// cleanup function
237-
};
228+
```js
229+
const destroy = $effect.root(() => {
230+
$effect(() => {
231+
// setup
238232
});
239-
</script>
233+
234+
return () => {
235+
// cleanup
236+
};
237+
});
238+
239+
// later...
240+
destroy();
240241
```
241242

242243
## When not to use `$effect`

0 commit comments

Comments
 (0)