Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
shivan-s committed Nov 7, 2024
1 parent 3ed6367 commit b39d38b
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions content/posts/svelte-5/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,34 @@ New:
<p>Hello, {nameToDisplay}</p>
```

### $effect()

Something to avoid, since we have [`$derived()`](<#$derived()>), but here is a simple example if we want to trigger a side effect (e.g. logging).

Old:

```svelte
<script>
let name = 'world'
$: {
console.log("Name changed: ", name)
}
</script>
<input bind:value={name} />
<p>Hello, {name}</p>
```

New:

```svelte
<script>
let name = $state('world')
$effect(()=> console.log("Name changed: ", name))
</script>
<input bind:value={name} />
<p>Hello, {name}</p>
```

## Snippets

0 comments on commit b39d38b

Please sign in to comment.