unstorage icon indicating copy to clipboard operation
unstorage copied to clipboard

How to perform mutations inside a store

Open Rednas83 opened this issue 1 year ago • 2 comments

Something like

store.patch({
  count: store.count + 1,
  age: 120,
  name: 'DIO',
})

OR

store.patch((state) => {
  state.items.push({ name: 'shoes', quantity: 1 })
  state.hasChanged = true
})

Rednas83 avatar Jun 08 '24 16:06 Rednas83

Sorry, just found it in the docs. Even possible with setItem I see. That's cool🚀 image

Not sure yet how to push to an array yet.

Something like this

store.patch((state) => {
  state.items.push({ name: 'shoes', quantity: 1 })
  state.hasChanged = true
})

Is that also possible?

Rednas83 avatar Jun 08 '24 16:06 Rednas83

Any thoughts?

Rednas83 avatar Jul 07 '24 07:07 Rednas83

unstorage is a KV database you need one getItem + one setItem

pi0 avatar Dec 18 '24 23:12 pi0