AsyncStorage
is a simple, asynchronous key-value pair used in React Native applications.- It is a local only storage.
- It comes in two parts: core and storage backend.
- Core is a consumer of the storage, provides you a unified API to save and read data.
- Storage backend implements an interface that core API understands and uses. Its functionality depends on storage itself.
Usage:
import AsyncStorage from '@react-native-community/async-storage';
// Store data
storeData = async () => {
try {
await AsyncStorage.setItem('@storage_Key', 'stored value')
} catch (e) {
// saving error
}
}
// Read data
getData = async () => {
try {
const value = await AsyncStorage.getItem('@storage_Key')
if(value !== null) {
// value previously stored
}
} catch(e) {
// error reading value
}
}