Migration
To migrate from the deprecated built-inAsyncStorage to the community package:
1. Install the Package
2. Update Imports
Change your import statements: Before:3. iOS Setup
For iOS, install the pods:4. Android Setup
No additional setup required for Android. The package will be automatically linked.Overview
AsyncStorage is an asynchronous, persistent, key-value storage system that is global to the app. It should be used instead of LocalStorage.Key Features
- Asynchronous API
- Persistent storage across app restarts
- Simple key-value pairs
- Supports large data sets
- Cross-platform (iOS and Android)
Limitations
- Stores only strings (serialize objects with JSON)
- Not encrypted by default
- Storage limits vary by platform
- Not suitable for large amounts of data (consider SQLite or Realm for complex data)
Basic API
The community package maintains the same API as the original AsyncStorage:setItem()
getItem()
null if not found.
removeItem()
mergeItem()
clear()
getAllKeys()
multiGet()
multiSet()
multiRemove()
Examples
Store and Retrieve String
Store and Retrieve Objects
Remove Item
Get All Keys
Clear All Data
Alternatives
For more advanced storage needs, consider:- Realm - Mobile database for complex data and relationships
- SQLite - SQL database for structured data
- MMKV - Fast, efficient key-value storage
- WatermelonDB - Reactive database for complex apps
- React Native Encrypted Storage - Encrypted key-value storage