最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Local Storage - React Native - Stack Overflow

programmeradmin9浏览0评论

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??

Share Improve this question asked May 31, 2020 at 11:33 groootgrooot 4662 gold badges12 silver badges33 bronze badges 1
  • Does this answer your question? How to store value in LocalStorage in React Native – Jony Commented Oct 20, 2022 at 18:12
Add a ment  | 

4 Answers 4

Reset to default 3

Async 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';
发布评论

评论列表(0)

  1. 暂无评论