--- title: Always Provide Unique Keys in v-for Loops impact: HIGH impactDescription: Missing or improper keys cause hard-to-debug bugs when list items have state, components, or animations type: gotcha tags: [vue3, v-for, list-rendering, key, state, components] --- # Always Provide Unique Keys in v-for Loops **Impact: HIGH** - Without proper keys, Vue cannot track element identity when lists change. This causes component state loss, incorrect animations, form input values jumping between items, and bugs that are extremely difficult to debug. The `key` attribute tells Vue how your data relates to the DOM elements it renders. When data ordering changes (via sort, filter, add, or remove), Vue uses keys to determine what to update, remove, or create. Without unique keys, Vue reuses DOM elements in-place which can cause one item's state to incorrectly appear on another item. ## Task Checklist - [ ] Always provide `:key` with unique, stable identifiers (database IDs, UUIDs) - [ ] Never use array index as key - indices shift when items are added/removed - [ ] Use primitive values only (strings or numbers) - never use objects as keys - [ ] On `