Setting up AsyncStorage in React Native Application
AsyncStorage is the simplest key-value storage for React Native. Asynchronous, unencrypted, stores strings. Suitable for user preferences, onboarding flags, lightweight data caching. Not suitable for authorization tokens (no encryption), large data volumes, complex queries.
Installation
Starting with React Native 0.59, AsyncStorage moved from core to a separate package:
npm install @react-native-async-storage/async-storage
For iOS: cd ios && pod install. For Android, linking is automatic.
Basic Usage
import AsyncStorage from '@react-native-async-storage/async-storage';
// Write
await AsyncStorage.setItem('onboarding_complete', 'true');
// Read
const value = await AsyncStorage.getItem('onboarding_complete');
// Objects — JSON only
await AsyncStorage.setItem('user_prefs', JSON.stringify({ theme: 'dark', lang: 'ru' }));
const prefs = JSON.parse(await AsyncStorage.getItem('user_prefs') ?? '{}');
// Delete
await AsyncStorage.removeItem('onboarding_complete');
// Batch operations
await AsyncStorage.multiSet([
['key1', 'value1'],
['key2', 'value2'],
]);
Android size limit. By default, AsyncStorage on Android is limited to 6 MB. Exceeding this causes Database size exceeded the quota error. Increase the limit via AndroidConfig in android/app/src/main/java/.../MainApplication.java:
new ReactNativeHost(this) {
@Override
protected List<ReactPackage> getPackages() {
// ...
}
}
Or set via AsyncStorageExtraConfig.setMaxSizeConfig in MainApplication. For larger storage needs, use react-native-mmkv (faster, no limits) or SQLite via react-native-quick-sqlite.
Type-Safe Wrapper
Direct getItem/setItem calls with JSON parsing scattered throughout code is bad practice. Wrap in a typed service:
const StorageService = {
async get<T>(key: string): Promise<T | null> {
const raw = await AsyncStorage.getItem(key);
return raw ? (JSON.parse(raw) as T) : null;
},
async set<T>(key: string, value: T): Promise<void> {
await AsyncStorage.setItem(key, JSON.stringify(value));
},
async remove(key: string): Promise<void> {
await AsyncStorage.removeItem(key);
},
};
What Not to Store in AsyncStorage
Authorization tokens — use react-native-keychain or expo-secure-store. They store data in iOS Keychain and Android Keystore — encrypted, protected by biometry.
Timeline
Installation and basic setup: 2–4 hours. With typed service and Redux Persist or Zustand integration: 4–8 hours. Cost calculated individually.







