Skip to content

docs: add untrack documentation, fixing part of #14058 #14060

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
[![Cybernetically enhanced web apps: Svelte](https://sveltejs.github.io/assets/banner.png)](https://svelte.dev)
<a href="https://svelte.dev">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="assets/banner_dark_large.png">
<img src="assets/banner_large.png" alt="Svelte - web development for the rest of us" />
</picture>
</a>

[![license](https://img.shields.io/npm/l/svelte.svg)](LICENSE.md) [![Chat](https://img.shields.io/discord/457912077277855764?label=chat&logo=discord)](https://svelte.dev/chat)

Expand Down
Binary file added assets/banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/banner_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/banner_dark_large.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/banner_large.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions documentation/docs/02-runes/04-$effect.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,26 @@ $effect(() => {
});
```

## `untrack`

As stated previously, dependencies are automatically tracked in an effect. To prevent a dependency from being tracked, `untrack` can be used. Unlike runes, `untrack` has to be imported from the `svelte` module. [Here](/playground/untitled#H4sIAAAAAAAACnXOwUrEMBDG8VcJw8K2bNn1XNvC-g6erIckTiVsmpTkqygh7y7Z6npQr__5DTOJnJyZWnp0MLD8Qg1NxnKk9ikRPpYyK4Gab3lelmN8Y4vSlIz8V9fegR0itdRFHcyCYXQjzLz4AJFWhyD1JYsp-Fnst7X9fSGWIaToxS5Cgqu7-lbVr7rjaWKNqqr7IZUwQnsXveWj9a-VbL7uXIGqt6Vcj6473Z7q1Ap4J7zT1uhLn4qVh0MezsJEkWTuThv5D6uCH65Y_WBqCPwOahFWzs_5E7FwwqtqAQAA)'s an example of its usage:

```svelte
<script>
import {untrack} from 'svelte';

let a = $state(0);
let b = $state(0);

$effect(()=>{
console.log(a,untrack(()=>b)); //this will only run when `a` changes
})
</script>

<button onclick={()=>a++}>A is {a}</button>
<button onclick={()=>b++}>B is {b}</button>
```

## `$effect.pre`

In rare cases, you may need to run code _before_ the DOM updates. For this we can use the `$effect.pre` rune:
Expand Down