Set up offline storage (AsyncStorage, MMKV)
✓Works with OpenClaudeYou are a mobile developer setting up offline storage for React Native. The user wants to implement persistent data storage using either AsyncStorage or MMKV, handling async operations and data serialization correctly.
What to check first
- Verify React Native version with
npm list react-native— AsyncStorage is community-maintained, MMKV requires native modules - Check if you have
@react-native-async-storage/async-storageorreact-native-mmkvinstalled; if not, runnpm install @react-native-async-storage/async-storageornpm install react-native-mmkv - For MMKV, ensure native build tools are available — run
pod installon iOS after installation
Steps
- Choose your storage backend: AsyncStorage for simple key-value storage (JSON serialization), MMKV for faster performance and complex data types
- Import the storage library at the top of your file —
import AsyncStorage from '@react-native-async-storage/async-storage'orimport { MMKV } from 'react-native-mmkv' - Create a storage service module that wraps read/write operations to handle errors consistently
- For AsyncStorage, use
JSON.stringify()before storing andJSON.parse()when retrieving objects - For MMKV, directly store strings, numbers, and booleans — use
getString(),getNumber(),getBoolean()for type-safe retrieval - Wrap AsyncStorage calls in try-catch blocks since it's async; MMKV operations are synchronous
- Initialize storage on app startup in your root component or app entry point, loading persisted user state
- Set up a cleanup or migration strategy for removing old keys when app versions change
Code
// storageService.js — Abstraction layer for both AsyncStorage and MMKV
import AsyncStorage from '@react-native-async-storage/async-storage';
import { MMKV } from 'react-native-mmkv';
const USE_MMKV = true; // Switch to false to use AsyncStorage
const mmkv = new MMKV();
export const storageService = {
// AsyncStorage implementation
async setAsync(key, value) {
try {
const jsonValue = JSON.stringify(value);
await AsyncStorage.setItem(key, jsonValue);
} catch (error) {
console.error(`Failed to save ${key}:`, error);
throw error;
}
},
async getAsync(key, defaultValue = null) {
try {
const jsonValue = await AsyncStorage.getItem(key);
return jsonValue != null ? JSON.parse(jsonValue) : defaultValue;
} catch (error) {
console.error(`Failed to retrieve ${key}:`, error);
return defaultValue;
}
},
async removeAsync(key) {
try {
await AsyncStorage.remove
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Mobile Skills
Other Claude Code skills in the same category — free to download.
React Native Screen
Create React Native screens with navigation
React Native Component
Build React Native UI components
Expo Setup
Set up Expo project with common configurations
Mobile Navigation
Set up React Navigation with typed routes
Push Notification
Implement push notifications (Expo/Firebase)
Mobile Auth Flow
Create mobile authentication flow
App Store Prep
Prepare app for App Store/Play Store submission
Deep Linking
Implement deep linking and universal links
Want a Mobile skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.