Let's think about it this way for a second
AsyncStorage is key-value storage that persists data on the device (it survives even after the app closes) — conceptually similar to a web browser's localStorage, but it's an asynchronous (Promise-based) API. Save with setItem(key, value), read with getItem(key), and delete with removeItem(key) — since values can only be stored as strings, you need to convert objects/arrays with JSON.stringify/JSON.parse.
Let's connect this to a real-world scenario
Store a user preference (theme, language) or a login token in AsyncStorage, and when the app closes and reopens, you don't need to show the login screen again — if a token exists, you can navigate straight to the Home screen (the auto-login pattern). Sensitive data (passwords, payment info) should never be stored as plain text in AsyncStorage — use encrypted storage (expo-secure-store) instead (remember the secret management concept from the Cybersecurity tutorial).
Code Example
import AsyncStorage from '@react-native-async-storage/async-storage';
// Save
const saveUserPrefs = async (prefs) => {
await AsyncStorage.setItem('userPrefs', JSON.stringify(prefs));
};
// Load
const loadUserPrefs = async () => {
const json = await AsyncStorage.getItem('userPrefs');
return json ? JSON.parse(json) : null;
};
// Remove
const clearUserPrefs = async () => {
await AsyncStorage.removeItem('userPrefs');
};Close and reopen the app, and you can read back the userPrefs that were saved in AsyncStorage.Try it in 5 minutes
Write two functions yourself that save/load a theme preference (light/dark) to and from AsyncStorage.
A quick word of caution
Data in AsyncStorage can be read by anyone with device root access (a rooted/jailbroken device) — for truly sensitive data (payment credentials), use only expo-secure-store or the platform's native secure storage.