Reputation: 466
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??
Upvotes: 5
Views: 6813
Reputation: 4027
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
Upvotes: 1
Reputation: 2777
It is moved to @react-native-community/async-storage
Install it and import it from lib:
import AsyncStorage from '@react-native-community/async-storage';
Upvotes: 2
Reputation: 16334
Async storage is not deprecated its moved to a separate package which you can install and use
https://github.com/react-native-community/async-storage/
Or for tokens you can use react-native-keychain which is a way secure package you can check it here. https://github.com/oblador/react-native-keychain
Upvotes: 3
Reputation: 2178
Async storage from react-native
library is deprecated, they split it from react-native core into a community 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-community/async-storage';
Upvotes: 0