Choosing between async and sync
Use sync methods for initialization
Sync methods eliminate loading states and provide instant access during component initialization:Use async methods for network coordination
When combining storage with API calls, async methods keep code consistent:Data size considerations
Keep values small
expo-native-storage is optimized for small key-value data:Platform-specific limits
iOS: ~1MB per key
iOS: ~1MB per key
UserDefaults is optimized for small values. Keep individual values under 1MB:
Android: No strict limit
Android: No strict limit
SharedPreferences loads all data into memory. Keep total storage size reasonable:
Web: 5-10MB per origin
Web: 5-10MB per origin
localStorage has strict quotas. Handle quota errors gracefully:
Error handling
Handle missing values gracefully
Always provide fallback values for missing keys:Wrap operations in try-catch
Handle potential errors when writing data:Type safety with TypeScript
Use generic types with objects
Provide type parameters for type-safe object storage:Create typed storage helpers
Build type-safe wrappers for common operations:Performance optimization
Cache values in memory
Avoid unnecessary reads by caching values in memory:Use batch operations
Batch multiple operations for better performance:Debounce frequent writes
Avoid writing on every change:Organizing storage keys
Use consistent naming conventions
Adopt a clear naming scheme for keys:Create key constants
Define keys as constants to avoid typos:Security considerations
Don’t store sensitive data unencrypted
expo-native-storage does not encrypt data. Use expo-secure-store for sensitive information:Validate data after reading
Always validate data read from storage:Testing
Mock storage in tests
Create a mock implementation for testing:Next steps
API Reference
Explore all available methods and their signatures.
Troubleshooting
Resolve common issues and errors.