[]previous and next page

Common mistakes

Common mistakes in the Lists and keys guide.

For agentsUpdated
  • Using the array index as the key. After an insert or a removal every key shifts; rows are reused for the wrong data. Use an id.
  • Rebuilding objects on every update (items().map((item) => ({ ...item }))) with an unkeyed For. Every reference is new, so every row is rebuilt. Keep references, or add key.
  • Treating item as an accessor in the unkeyed form, or as a value in the keyed form. Unkeyed: item.title. Keyed: item().title. Index always gives an accessor.
  • Using Index for objects that get reordered. Position rows rewrite item() on every row instead of moving nodes.
  • Mutating the array in place outside a store (list().push(x)). Nothing notifies. Write a new array to the signal, or use a store.
  • A key that is not stable (key={() => Math.random()}, a fresh object). Rows are rebuilt on every update.