Skip to content

Commit

Permalink
docs: fix $effect.pre code example
Browse files Browse the repository at this point in the history
closes #12439
  • Loading branch information
dummdidumm committed Jul 15, 2024
1 parent b27113d commit ad895dc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
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

0 comments on commit ad895dc

Please sign in to comment.