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

Clear the store

needdoneapp opened this issue · comments

+1 on this. Anyway to clear the whole store?

Actually you can do this pretty easily...

import Store from 'react-native-simple-store'
Store.keys()
   .then( keys => Promise.all(keys.map(key => Store.delete(key))) )
   .then( () => console.log('All storage keys deleted') )
   .catch(console.error)

@ChrisPikul510 Looks like you found a pretty good way to do that. Looking through the code it seems that .get and .save take an array as well to update multiple keys. It would probably be nice to be able to pass an array to .delete in order to delete multiple keys. That way you could just do something like.

try {
  const keys = await store.keys();
  await store.delete(keys);
  console.log('All storage keys deleted');
} catch (error) {
  console.error(error);
}

I'll work on adding that in soon.

#28 should accomplish this.

@ChrisPikul510 @needdoneapp this has been released with #28, tagged and released as v1.2.0 to NPM.

for someone who meet this issue try use AsyncStorage.clear()
up to you what version you want to try use