AsyncStorage

AsyncStorage is a simple, unencrypted, asynchronous, persistent, key-value storage system that is global to the app. It should be used instead of LocalStorage.

It is recommended that you use an abstraction on top of AsyncStorage instead of AsyncStorage directly for anything more than light usage since it operates globally.

On iOS, AsyncStorage is backed by native code that stores small values in a serialized dictionary and larger values in separate files. On Android, AsyncStorage will use either RocksDB or SQLite based on what is available.

The AsyncStorage JavaScript code is a simple facade that provides a clear JavaScript API, real Error objects, and simple non-multi functions. Each method in the API returns a Promise object.

multiGet()

This allows you to batch the fetching of items given an array of key inputs. Your callback will be invoked with an array of corresponding key-value pairs found:

multiGet(['k1', 'k2'], cb) -> cb([['k1', 'val1'], ['k2', 'val2']])

The method returns a Promise object.

Parameters:

Name

Type

Required

Description

keys

Array

Yes

Array of key for the items to get.

callback

?(errors: ?Array, result: ?Array<Array>) => void

No

Function that will be called with a key-value array of the results, plus an array of any key-specific errors found.

Example:

AsyncStorage.getAllKeys((err, keys)=>{
AsyncStorage.multiGet(keys,(err, stores)=>{
stores.map((result, i, store)=>{// get at each store's key/value so you can work with itlet key = store[i][0];let value = store[i][1];});});});