Those who come from a Native environment are used to persistent storage, such as databases or files. So far, any time our app has been relaunched, it has lost its state. We can fix that using system storage.
For this purpose, we will use the AsyncStorage API that comes with React Native:
"On iOS, AsyncStorage is backed by native code that stores small values in a serialized dictionary and larger values in separate files. On Android, AsyncStorage will use either RocksDB or SQLite based on what is available."
- From the React Native official documentation, which can be found at:
https://facebook.github.io/react-native/docs/asyncstorage.html.
- From the React Native official documentation, which can be found at:
https://facebook.github.io/react-native/docs/asyncstorage.html.
The AsyncStorage API is pretty easy to use. First, let's save the data:
import { AsyncStorage } from 'react-native';
try {
await AsyncStorage.setItem('@MyStore:key',...