Skip to content

Can't delete nested object from store #23

@btzr-io

Description

@btzr-io

When used with unistore is impossible to delete / remove a nested object or property.
See the following example ( This code only works using unistore without stockroom )

// Store
const state = {
  collections: {
     items: {
        a: { ... },
        b: { ... },
        c: { ... },
     }
    // ...
  }
 // ...
}

// Action
removeItem({ collections }, id) {
      let items = collections.items;
      // Remove item
      if (items[id]) {
        const { [id]: removed, ...rest } = items;
        items = rest;
      }
    return { collections: { ...collections, items } };
},

Unistore only example (working demo)

Edit Unistore Demo

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions