maz32
maz32

Reputation: 137

React Native Expo shows Async Storage warning

i'm using React Native expo, and it shows

[Warning: Async Storage has been extracted from react-native core and will be removed in a future release. It can now be installed and imported from '@react-native-community/async-storage' instead of 'react-native'. See https://github.com/react-native-community/react-native-async-storage].

i read this link and I understood that it's due to the fact that some dependencies are using old AsyncStorage, not the new one from community. But I hardly found that any solution for Expo users. Is there any solution for Expo? Or if I have to manual change dependencies using the old AsyncStorage, how can i do it? Since I'm new to React Native, not really sure what to do..

Upvotes: 0

Views: 4607

Answers (4)

Siddhartha Mukherjee
Siddhartha Mukherjee

Reputation: 2961

it's working, You can try it.

npx expo install @react-native-async-storage/async-storage

// Usage
import AsyncStorage from '@react-native-async-storage/async-storage';

await AsyncStorage.setItem('@storage_Key', value);
await AsyncStorage.getItem('@storage_Key');

https://react-native-async-storage.github.io/async-storage/docs/install

Upvotes: 0

Mak12
Mak12

Reputation: 21

This error occurs because firebase imports AsyncStorage from react native core and not the new library @react-native-async-storage/async-storage. I think firebase hasn't updated the by default import yet so you have to do it yourself.The way I fixed it was ;

  • Install react-native-async-storage: npm i @react-native-async-storage/async-storage
  • Go into the firebase index.js file that imports AsyncStorage from react native core: It is located at : 'node_modules/@firebase/auth/dist/rn'.
  • Create a variable that imports AsycnStorage from 'node-modules/@react-native-async-storage/async-storage' : var AsyncStorage = require('../../../../@react-native-async-storage/async-storage');
  • Replace all uses of AsyncStorage in this file from react native core with new variable, i.e. replace "ReactNative__namespace.AsyncStorage" with "AsycnStorage",

Upvotes: 0

Carmine Tambascia
Carmine Tambascia

Reputation: 1938

Now expo has migrated to use as well the community version as you can see here.

But if you get this warning definitely you have some dependency or more that still use the react-native-core version, if so please refer to the first answer to How to resolve using AsyncStorage (deprecated) warning? Using the community (correct) library:

if this is the case the best is as suggested in that answer is to

Your best course of action is to fork the repo and fix all instances of AsyncStorage to use the correct version, or open an issue.

Upvotes: 0

Christian
Christian

Reputation: 4641

In Expo you should always link the libraries that Expo includes in the App. So like mentioned in the docs here https://docs.expo.dev/versions/latest/sdk/async-storage/

expo install @react-native-async-storage/async-storage

is the correct import. If you are working with an old Expo-SDK this might be different, otherwise you should adapt your imports.

Upvotes: 3

Related Questions