Already installed @react-native-async-storage/async-storage with expo install but deprication warning won't go away

Viewed 1789

I have this warning in React Native Expo: AsyncStorage 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-async-storage/async-storage' instead of 'react-native'. See https://github.com/react-native-async-storage/async-storage

I have installed @react-native-async-storage/async-storage with expo install but the warning won't go away.

A search of my files shows no result for AsyncStorage What am I doing wrong, please advice

"dependencies": {
    "@react-navigation/native": "^6.0.6",
    "@react-navigation/native-stack": "^6.2.5",
    "expo": "~43.0.2",
    "expo-firebase-recaptcha": "~2.0.2",
    "expo-status-bar": "~1.1.0",
    "firebase": "^9.5.0",
    "react": "17.0.1",
    "react-dom": "17.0.1",
    "react-native": "0.64.3",
    "react-native-safe-area-context": "3.3.2",
    "react-native-screens": "~3.8.0",
    "react-native-web": "0.17.1",
    "react-native-webview": "11.13.0"
  }
2 Answers

Even though this is a problem with how the firebase package imports AsyncStorage internally, there is a workaround that will let you clear that warning for now, until firebase imports AsyncStorage correctly. The solution uses getReactNativePersistence() method from the auth module.

We can use this method to pass the correct import of AsyncStorage, and then firebase won't have to import it from react-native internally, thus fixing this warning. Here is one way to do it:

import { getApp, getApps, initializeApp } from "firebase/app";
import { getAuth, initializeAuth } from "firebase/auth";
import { getReactNativePersistence } from 'firebase/auth/react-native';
import AsyncStorage from '@react-native-async-storage/async-storage';

const firebaseConfig = {
   ...
};

// Initialize Firebase
let app;
let auth;
if (getApps().length < 1) {
  app = initializeApp(firebaseConfig);
  auth = initializeAuth(app, {
    persistence: getReactNativePersistence(AsyncStorage),
  });
} else {
  app = getApp();
  auth = getAuth();
}

export { app, auth };

Adopted from: Firebase Issue 1847#issuecomment-1041548028

Related