Skip to content

docs: fix $effect.pre code example #12444

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

Merged
merged 1 commit into from
Jul 15, 2024
Merged
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
8 changes: 4 additions & 4 deletions documentation/docs/03-runes/02-side-effects.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,16 +245,16 @@ In rare cases, you may need to run code _before_ the DOM updates. For this we ca
<script>
import { tick } from 'svelte';

let div;
let messages = [];
let div = $state();
let messages = $state([]);

// ...

$effect.pre(() => {
if (!div) return; // not yet mounted

// reference `messages` so that this code re-runs whenever it changes
messages;
// reference `messages` array length so that this code re-runs whenever it changes
messages.length;

// autoscroll when new messages are added
if (div.offsetHeight + div.scrollTop > div.scrollHeight - 20) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,16 +453,16 @@ In rare cases, you may need to run code _before_ the DOM updates. For this we ca
<script>
import { tick } from 'svelte';

let div;
let messages = [];
let div = $state();
let messages = $state([]);

// ...

$effect.pre(() => {
if (!div) return; // not yet mounted

// reference `messages` so that this code re-runs whenever it changes
messages;
// reference `messages` array length so that this code re-runs whenever it changes
messages.length;

// autoscroll when new messages are added
if (
Expand Down
Loading