React Native theorytheory 0/50 · 0%
Storage · easy

14. AsyncStorage and persistence

Key-value storage across app launches.

`@react-native-async-storage/async-storage` provides a simple, asynchronous key-value store persisted on disk — good for caching non-sensitive data like a selected chain or theme preference.

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

async function saveChain(chainId: number) {
  await AsyncStorage.setItem("chainId", String(chainId));
}

async function loadChain(): Promise<number | null> {
  const v = await AsyncStorage.getItem("chainId");
  return v ? Number(v) : null;
}

Never store a private key or seed phrase in AsyncStorage — it is unencrypted. Use `react-native-keychain` or a secure enclave-backed library for secrets.

Check your understanding

  1. 1. Is AsyncStorage encrypted?

  2. 2. What should you use to store a wallet private key?

  3. 3. What kind of API does AsyncStorage expose?