search

Home  >  Q&A  >  body text

Why is the Vue component not re-rendered after changing the Pinia state (removing the object in the array)?

I have a deleteHandler function that changes the users array in pinia. However, in vue's devtools, the state changes but the component is not re-rendered, but if I remove the object from the array, just change some values, then vue recognizes it and re-renders the component, just by removing it from the array Objects won't work.

const deleteHandler = (user) => {
  //doesn't renders
    useUser.users = useUser.users.filter(usr => usr.id !== user.id) 
  //it works, the component is re-rendered
  useUser.users.forEach(usr => {
    usr.points += 1
  })
}

P粉763748806P粉763748806348 days ago444

reply all(1)I'll reply

  • P粉337385922

    P粉3373859222023-12-31 00:26:29

    I think this is some kind of reference issue. Please try this

    useUser.users = [...useUser.users.filter(usr => usr.id !== user.id)];

    Installed

    useUser.users = useUser.users.filter(usr => usr.id !== user.id)

    reply
    0
  • Cancelreply