Recall & Review
beginner
What is a keyed each block in Svelte?
A keyed each block in Svelte is a way to loop over a list where each item is tracked by a unique key. This helps Svelte update only the changed items in the list, improving performance and keeping the UI in sync.
Click to reveal answer
beginner
Why should you use a key in an each block?
Using a key helps Svelte identify which items changed, moved, or were removed. This prevents unnecessary re-rendering and keeps animations and transitions smooth.
Click to reveal answer
beginner
How do you write a keyed each block in Svelte?
You write it like this: <br>
{#each items as item (item.id)} <br> The part in parentheses is the key, usually a unique id from the item.Click to reveal answer
intermediate
What happens if you don’t use keys in an each block?
Svelte will update the list by position, which can cause wrong items to update or lose their state. This can lead to bugs or weird UI behavior.
Click to reveal answer
intermediate
Can you use any value as a key in a keyed each block?
The key should be a unique and stable value for each item, like an id. Using indexes or non-unique values can cause problems when the list changes.
Click to reveal answer
What is the main benefit of using a keyed each block in Svelte?
✗ Incorrect
Keyed each blocks let Svelte know which items changed by using unique keys, so it updates only those items.
How do you specify the key in a Svelte each block?
✗ Incorrect
The key is placed in parentheses after the item in the each block syntax.
What can happen if you use the array index as a key?
✗ Incorrect
Using indexes as keys can confuse Svelte when items move or change, causing wrong updates.
Which of these is a good choice for a key in a keyed each block?
✗ Incorrect
A unique and stable id ensures Svelte can track each item correctly.
If you omit the key in an each block, what does Svelte do?
✗ Incorrect
Without keys, Svelte updates list items by their order, which can cause UI issues.
Explain what a keyed each block is in Svelte and why it is useful.
Think about how Svelte tracks list items when they change.
You got /3 concepts.
Describe how to write a keyed each block in Svelte with an example.
Remember the parentheses after the item in the each block.
You got /3 concepts.