[Vuejs]-Deleting an object using its ID from pinia array

0👍

countdowns shouldn’t be reassigned, it’s a constant and it can’t be reactive the other way.

The problem here is that it was destructured from the state without a good reason.

It should be either:

const main = useCountdownStore();
const deleteCountdown = (e) => {
  main.countdowns = main.countdowns.filter((countdown) => {
      countdown.id != e.targt.parentElement.id;
    });
};

Or used as a ref:

const main = useaCountdownStore();
const { countdowns } = toRefs(main);

const deleteCountdown = (e) => {
  countdowns.value = countdowns.value.filter((countdown) => {
      countdown.id != e.targt.parentElement.id;
    });
};

deleteCountdown itself implements store logic outside the store, it should preferably be transformed to store action.

Leave a comment