-
So I have an Alpine store with an array of items, I have a x-for template to display those items on the page, there is a button to remove a given item from the array. The issue is that no matter which element is removed from the array the last element in the x-for template is removed. example:
Thanks for any suggestions you may have! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You need a unique key on your template tag (https://alpinejs.dev/directives/for#keys). |
Beta Was this translation helpful? Give feedback.
You need a unique key on your template tag (https://alpinejs.dev/directives/for#keys).
Do not use
index
because it's important that the key identifies the same element on each iteration.In your example, it would be
<template x-for="(item, index) in items" :key="item.name">