Installation
Setup
Configuration
The AsyncStorage instance from
@react-native-async-storage/async-storagePreload data on initialization for faster startup
Usage
Basic Usage
With Preload
Plugin API
The AsyncStorage plugin implements theObservablePersistPlugin interface:
initialize()
loadTable()
getTable()
set()
getMetadata()
setMetadata()
deleteTable()
deleteMetadata()
Examples
Complete App Setup
User Session
App Settings
Shopping Cart
Multi-Account
Offline Support
Clear User Data on Logout
Storage Format
Data is stored as JSON strings:Performance
Without Preload
With Preload
Best Practices
- Use preload: Load critical data on app startup
- Namespace keys: Use descriptive, unique names
- Handle errors: AsyncStorage operations can fail
- Consider MMKV: For better performance, use MMKV plugin
- Clear on logout: Remove sensitive data when user logs out
When to Use
Use AsyncStorage when:- Standard React Native persistence is sufficient
- Data size is moderate (< 6MB)
- You don’t need synchronous access
- Cross-platform compatibility is important
- You need better performance
- Synchronous access is required
- Data is accessed frequently
See Also
- MMKV Plugin - Faster alternative for React Native
- localStorage Plugin - For web
- synced() - Create synced observables
- configureObservableSync() - Global configuration