22 lines
No EOL
544 B
Markdown
22 lines
No EOL
544 B
Markdown
extras
|
|
|
|
about effect rune
|
|
|
|
```js
|
|
<script>
|
|
let count = $state(0);
|
|
let doubled = $derived(count * 2);
|
|
let triggerValue = $state('initial');
|
|
|
|
// This runs whenever any reactive value used inside changes
|
|
$effect(() => {
|
|
console.log('Effect ran:', count, doubled);
|
|
});
|
|
|
|
// This will only run when triggerValue changes
|
|
$effect(() => {
|
|
console.log('Triggered effect:', triggerValue);
|
|
// You can use other values here, but it won't re-run when they change
|
|
}).with(triggerValue);
|
|
</script>
|
|
``` |