AsyncStorage Handler
An improved form of working with react-native asyncstorage.
Getting Started
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.
Prerequisites
This handler works strictly with react native. Works with both the
create-react-app <app-name>
and the
react-native init <app-name>
of react native.
Installing
To Install the handler
npm install asyncstoragehandler --save
Usage
1.Import asyncstoragehandler:
2.Set one of the states in the constructor to be the handler:
{ super; thisstate = Handler : }
Complete Example
A complete example on saving data.
;;; state = Handler: ; _setData = async let data = title : "handler test" thisstateHandler ; { return <View style= flex: 1 > <TouchableOpacity onPress=this_setData> <Text>Save Data</Text> </TouchableOpacity> </View> ; }
Functions and Description
Functions | Description |
---|---|
setItem(key: string, value: string) | Persist a value to asyncStorage for a key. Returns a Promise object |
setItemArray(key: string, value: string) | Persist an array value to asyncStorage for a key. Returns a Promise object |
getItem(key: string) | Gets an item (including array) for a key. Returns a Promise object |
updateItem(key: string, value: string) | Updates a value to asyncStorage for a key. Returns a Promise object |
updateItemArray(key: string, index: integer, value: string) | Update an element from the array value for a key. Returns a Promise object |
deleteItem(key: string) | Removes an item for a key . Returns a Promise object. |
deleteItemArray(key: string, index: integer) | Removes an element from the array value for a key. Returns a Promise object |
clearAllItem(key: string) | Erases all Item for all clients, libraries, etc. Returns a Promise object. |
Authors
License
This project is licensed under the MIT License - see the LICENSE.md file for details
Acknowledgments
- Hat tip to anyone whose code was used directly or indirectly.
- Inspiration
- etc