-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Feature request: Ability to key a non-each component #1469
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I would like to see this as well. <script>
let key = 1;
setInterval(() => {
key++;
}, 1000);
</script>
{#each [key] as k (k)}
<div>
{Math.random()}
</div>
{/each} |
Ha oh duh, that's clever; wish I'd thought of that. |
This would be nice! But great workaround! |
So it's not lost in Discord: https://discordapp.com/channels/457912077277855764/506988048375087114/607596367577088035 |
|
Agreed, I think |
+1 for Meanwhile, I wrapped the workaround into a component and published it as an npm package: https://github.com/rixo/svelte-key |
I agree about I'd be happy to take on the work of implementing if this proposal gets approved. |
This would be handy. I've resorted to using a fake array with one element as @dodas suggested for a router I'm working on:
|
When changing page, but in the same component, the page was not refreshed. There was these two issues: * No transition * Some part of the page is not updated The reason was because Svelte reused the exact same component (so no mount / destroy and no animation on component creation / destruction). To correctly update the page, we change the `Page` component by adding a keyed-each block (see sveltejs/svelte#1469). There was some issue with this solution because each time we update the component, the render is updated so the Page and create an infinite loop. To avoid this problem, we remove the call to `Page` component from concrete pages and include it directly with the Router. To do so, we create the PageRoute component behaving as expected.
I second this. Could be useful in animating list items outside an <div class="grid">
{#each items as item, index (item.id)}
<div animate:flip
transition:fade
class="grid-item"
on:click={() => deleteItem(index)}
>
{item.value}
</div>
{/each}
<button class="add-new" on:click={addItem}>
Add item
</button> <!-- Cannot apply animation to this element -->
</div> |
You can now do |
It would be handy if we could force recreation of components sometimes, even if they're not within an each block.
For example, in react I could have used a key to workaround my issue in #1467 and force the component to remake itself from scratch and readd the defaults.
Thanks again!
The text was updated successfully, but these errors were encountered: