react-native-async-storage
react-native-async-storage library, which you should use for any apps built with Vega version 0.8 or later. Previous versions of Vega use AsyncStorage as a React Native API, but will be deprecated in a future release.@amazon-devices/react-native-async-storage__async-storage is an extension of react-native-async-storage/async-storage that enables its use in React Native for Vega apps. The library supports an asynchronous, unencrypted, persistent, key-value storage system for React Native for Vega apps and is usable in both TypeScript and JavaScript.
This library is system-deployed and available to React Native for Vega apps without a separate installation process. The library is deployed as an autolinking library, which your app links to at runtime. The library is guaranteed to be compatible only with the version of React Native for Vega for which it's built.
When you uplevel your app's version of React Native for Vega, consider the best practice of upleveling its library dependencies.
Install the library
- Add the JavaScript library dependency in your app's
package.json."dependencies": { ... "@amazon-devices/react-native-async-storage__async-storage": "~2.0.2+1.23.1", "@react-native-async-storage/async-storage": "1.23.1", ... } - Reinstall the
package-lock.jsonfile using thenpm installcommand.
Examples
Storing data
Storing the string value
import React from "react";
import AsyncStorage from '@react-native-async-storage/async-storage';
const storeData = async (value) => {
try {
await AsyncStorage.setItem('my-key', value);
} catch (e) {
// saving error
}
};
Storing the object value
import AsyncStorage from '@react-native-async-storage/async-storage';
const storeData = async (value) => {
try {
const jsonValue = JSON.stringify(value);
await AsyncStorage.setItem('my-key', jsonValue);
} catch (e) {
// saving error
}
};
Reading data
Reading the string value
import AsyncStorage from '@react-native-async-storage/async-storage';
const getData = async () => {
try {
const value = await AsyncStorage.getItem('my-key');
if (value !== null) {
// value previously stored
}
} catch (e) {
// error reading value
}
};
Reading the object value
import AsyncStorage from '@react-native-async-storage/async-storage';
const getData = async () => {
try {
const jsonValue = await AsyncStorage.getItem('my-key');
return jsonValue != null ? JSON.parse(jsonValue) : null;
} catch (e) {
// error reading value
}
};
API reference
| Prop | Description | Default |
|---|---|---|
getItem |
Gets a string value for given key. This function can either return a string value for existing key or return null otherwise. In order to store object value, you must deserialize it, for example using JSON.parse(). Note (legacy): you can use an optional callback as an alternative for a returned promise. |
None |
setItem |
Sets a string value for given key. This operation can either modify an existing entry, if it did exist for given key, or add new one otherwise. In order to store object value, you must serialize it, for example using JSON.stringify(). Note (legacy): you can use an optional callback as an alternative for a returned promise. |
None |
mergeItem |
Merges an existing value stored under key, with new value, assuming both values are stringified JSON. | None |
removeItem |
Removes item for a key, invokes (optional) callback once completed. | None |
getAllKeys |
Returns all keys known to your App, for all callers, libraries, etc. Once completed, invokes callback with errors (if any) and array of keys. | None |
multiGet |
Fetches multiple key-value pairs for given array of keys in a batch. Once completed, invokes callback with errors (if any) and results. | None |
multiSet |
Stores multiple key-value pairs in a batch. Once completed, a callback with any errors get called. | None |
multiMerge |
Multiple merging of existing and new values in a batch. Assumes that values are stringified JSON. Once completed, invokes callback with errors (if any). | None |
multiRemove |
Clears multiple key-value entries for given array of keys in a batch. Once completed, invokes a callback with errors (if any). | None |
clear |
Removes whole AsyncStorage data, for all clients, libraries, etc. You probably want to use removeItem or multiRemove to clear only your App's keys. | None |
useAsyncStorage |
Note: An experimental hooks-like interface. This interface will change in the future to fully leverage the Hooks API, so feel free to follow this discussion to learn more. The useAsyncStorage hook returns an object that exposes all methods that allow you to interact with the stored value. |
None |
For more details and usage examples, see react-native-async-storage/async-storage library's documentation.
Supported versions
| Package name | Amazon NPM library version | Vega OS build number | Vega SDK version | Release notes |
|---|---|---|---|---|
@amazon-devices/react-native-async-storage__async-storage |
2.0.0+2.13.0 | OS 1.1 (201010438050) |
0.20 |
Additional resources
For information on other libraries, see Supported Third-Party Libraries and Services.
Last updated: Oct 01, 2025

