{#key} for Forcing Re-render
Use the key block to destroy and recreate components when a value changes.
The key Block
{#key expr} destroys and recreates its contents whenever expr changes. Useful when you want a fresh component.
Restart Animations
Wrap an animated element in {#key} to replay the transition each time the key changes.
{#key id}
<div in:fade>{message}</div>
{/key}All lessons in this course
- {#if} {#else if} {#else}
- {#each} with Index and Key
- {#key} for Forcing Re-render
- Nested {#each} and Keyed Updates