You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
svelte/packages/svelte/tests/runtime-runes/samples/each-bind-this-member-2/main.svelte

24 lines
411 B

<script>
import Child from './Child.svelte';
let items = $state([]);
function add_item() {
items.push({
id: items.length,
text: 'Item ' + (items.length + 1),
dom: null,
})
}
function clear() {
items = [];
}
</script>
<button on:click={add_item}>add item</button>
<button on:click={clear}>clear</button>
{#each items as item, index (item.id)}
<Child bind:item={items[index]} />
{/each}