Overview - Keyed each blocks
What is it?
In Svelte, a keyed each block is a way to loop over a list of items and tell Svelte how to track each item uniquely using a key. This helps Svelte know which items changed, moved, or stayed the same when the list updates. Instead of just re-rendering everything, Svelte can update only the parts that really changed. This makes your app faster and smoother.
Why it matters
Without keyed each blocks, Svelte might replace or reorder list items inefficiently, causing flickers or losing input focus in forms. Keyed each blocks solve this by letting Svelte match items by their unique keys, so updates feel natural and fast. This is important for user experience, especially in dynamic lists like chats, to-do lists, or live data feeds.
Where it fits
Before learning keyed each blocks, you should understand basic Svelte syntax, how to create simple each blocks, and how reactivity works. After mastering keyed each blocks, you can explore advanced list animations, transitions, and state management techniques that rely on stable item identity.