mirror of https://github.com/sveltejs/svelte
parent
85268bc147
commit
0ad95885f3
@ -1,17 +1,20 @@
|
|||||||
<script>
|
<script>
|
||||||
let count = $state(1);
|
let count = $state(1);
|
||||||
let derived_value = $derived(count * count);
|
let squared = $derived(count * count);
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
console.log(`$effect: ${derived_value}`);
|
console.log(`count: ${count}`);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
console.log(`$effect teardown: ${derived_value}`);
|
console.log(`squared: ${squared}`);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<button id="increment" onclick={() => count++}>Increment s</button>
|
<button onclick={() => count++}>increment</button>
|
||||||
<button id="overwrite" onclick={() => (derived_value = 7)}>Overwrite derived_value</button>
|
|
||||||
|
|
||||||
<p>count: {count}</p>
|
<p>count: {count}</p>
|
||||||
<p>derived_value: {derived_value}</p>
|
|
||||||
|
{#if count % 2 === 0}
|
||||||
|
<p id="squared">squared: {squared}</p>
|
||||||
|
{/if}
|
||||||
|
Loading…
Reference in new issue