As Async Storage is deprecated what other way is there to store a variable locally??
I have a React Native ios App with a Notification Centre.
Each time the user enters the Notification Centre a Cognito access Token was generated. To avoid excess of token generation the Tokens were saved through Async storage and their expiry was checked.
Now is there some other local storage in React Native that i can use??
As Async Storage is deprecated what other way is there to store a variable locally??
I have a React Native ios App with a Notification Centre.
Each time the user enters the Notification Centre a Cognito access Token was generated. To avoid excess of token generation the Tokens were saved through Async storage and their expiry was checked.
Now is there some other local storage in React Native that i can use??
- Does this answer your question? How to store value in LocalStorage in React Native – Jony Commented Oct 20, 2022 at 18:12
4 Answers
Reset to default 3Async storage is not deprecated its moved to a separate package which you can install and use
https://github./react-native-munity/async-storage/
Or for tokens you can use react-native-keychain which is a way secure package you can check it here. https://github./oblador/react-native-keychain
It is moved to @react-native-munity/async-storage
Install it and import it from lib:
import AsyncStorage from '@react-native-munity/async-storage';
AsyncStorage is deprecated so use below package
Get library With Yarn:
yarn add @react-native-async-storage/async-storage
Once done, import the header
import AsyncStorage from '@react-native-async-storage/async-storage';
For store a value
const storeData = async (value) => {
try {
await AsyncStorage.setItem('@storage_Key', value)
} catch (e) {
// saving error
}
}
Get a Value
const getData = async () => {
try {
const value = await AsyncStorage.getItem('@storage_Key')
if(value !== null) {
// value previously stored
}
} catch(e) {
// error reading value
}
}
For more: offical link
Async storage from react-native
library is deprecated, they split it from react-native core into a munity library.
You can always use Async Storage from this library
Just follow installation steps from docs. And you can import AsyncStorage
like this
import AsyncStorage from '@react-native-munity/async-storage';