jasonmerino / react-native-simple-store

A minimalistic wrapper around React Native's AsyncStorage.

Home Page:https://www.npmjs.com/package/react-native-simple-store

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

store.delete delete by ID

shiroze opened this issue · comments

if I have key array structure like this

'Bookmark' = {[ ID : 1, isBooked: true ],[ ID : 3, isBooked: true ]}

I want delete / remove ID : 1, how to do it ?

Assuming you had a structure like this:

const Bookmark = [{
  ID: 1,
  isBooked: true
}, {
  ID: 3,
  isBooked: true
}];

And that was stored in simple store you would do something like this to delete it and save it back to simple store.

async function deleteBookmarkById(id) {
  const bookmark = await store.get('bookmark');
  const newBookmarks = bookmark.filter((b) => b.ID !== id);
  await store.save('bookmark', newBookmarks);
  return newBookmarks;
}