AsyncStorage # | Edit on GitHub |
AsyncStorage is a simple, 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. This JS code is a simple facade that
provides a clear JS API, real Error objects, and simple non-multi functions. Each
method returns a Promise object.
Fetches key and passes the result to callback, along with an Error if
there is any. Returns a Promise object.
Sets value for key and calls callback on completion, along with an
Error if there is any. Returns a Promise object.
Returns a Promise object.
Merges existing value with input value, assuming they are stringified json.
Returns a Promise object. Not supported by all native implementations.
Example:
Erases all AsyncStorage for all clients, libraries, etc. You probably
don't want to call this - use removeItem or multiRemove to clear only your
own keys instead. Returns a Promise object.
Gets all keys known to the app, for all callers, libraries, etc. Returns a Promise object.
Example: see multiGet for example
Flushes any pending requests using a single multiget
multiGet invokes callback with an array of key-value pair arrays that
matches the input format of multiSet. Returns a Promise object.
multiGet(['k1', 'k2'], cb) -> cb([['k1', 'val1'], ['k2', 'val2']])
Example:
multiSet and multiMerge take arrays of key-value array pairs that match
the output of multiGet, e.g. Returns a Promise object.
multiSet([['k1', 'val1'], ['k2', 'val2']], cb);
Example: see multiMerge for an example
Delete all the keys in the keys array. Returns a Promise object.
Example:
Merges existing values with input values, assuming they are stringified
json. Returns a Promise object.
Not supported by all native implementations.
Example:
Examples # | Edit on GitHub |