A wrapper for React-Native AsyncStorage
npm i --save react-native-key-value-store
import Storage from 'react-native-key-value-store';
let value = await Storage.get('foo', 'default value');
console.log(value); // should be default value if foo hasn't already been set
await Storage.set('foo', 'bar');
value = await Storage.get('foo');
console.log(value); // should be 'bar' as it has been set
All methods on the
KeyValueStore
areasync
and therefore returnpromises
.
This will get a value based on the key provided. You can also set a default value in case the key does not exist in the store.
This will set a value based for the key provided.
This will merge a value into the existing value in storage
This will delete the key from the store.
This will return an array of all keys in the store.
The default key value store has a namespace of @Default
You can create your own key value stores with different namespaces
import { KeyValueStore } from 'react-native-key-value-store';
const appStore = new KeyValueStore('@App');
This will allow you to isolate different key/values, and will also affect the
return value from keys()
method, as it will check the namespace.
react-native-key-value-store is licensed with the MIT license.
See LICENSE for more details.