R
Rishtaara
React Native Fundamentals
Lesson 15 of 20Article14 min

AsyncStorage & Local Persistence

@react-native-async-storage/async-storage is an asynchronous, persistent key-value store. Use for auth tokens, user preferences, and offline cache. For sensitive data prefer react-native-keychain.

Storing data on device

@react-native-async-storage/async-storage is an asynchronous, persistent key-value store. Use for auth tokens, user preferences, and offline cache. For sensitive data prefer react-native-keychain.

AsyncStorage helpers
import AsyncStorage from "@react-native-async-storage/async-storage";

export async function saveToken(token: string) {
  await AsyncStorage.setItem("auth_token", token);
}

export async function getToken() {
  return AsyncStorage.getItem("auth_token");
}

export async function saveCache<T>(key: string, data: T) {
  await AsyncStorage.setItem(key, JSON.stringify(data));
}

export async function loadCache<T>(key: string): Promise<T | null> {
  const raw = await AsyncStorage.getItem(key);
  return raw ? JSON.parse(raw) : null;
}

When to use what

  • AsyncStorage — tokens, settings, small JSON cache (< 6MB per key on Android).
  • Keychain / EncryptedStorage — passwords, refresh tokens, PII.
  • SQLite / WatermelonDB — large structured offline datasets.
  • MMKV — fast key-value alternative for performance-critical reads.