已经使用 expo install 安装了 @react-native-async-storage/async-storage 但贬值警告不会消失

Deo*_*azy 5 firebase react-native expo

我在 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

我已经安装了@react-native-async-storage/async-storageexpo install但警告不会消失。

搜索我的文件没有显示“AsyncStorage我做错了什么,请建议”的结果

"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"
  }
Run Code Online (Sandbox Code Playgroud)

erf*_*fan 6

尽管这是 firebase 包如何在内部导入 AsyncStorage 的问题,但有一种解决方法可以让您暂时清除该警告,直到 firebase 正确导入 AsyncStorage。该解决方案使用auth 模块中的getReactNativePersistence()方法。

我们可以使用此方法来传递 AsyncStorage 的正确导入,然后 firebase 就不必从react-native内部导入它,从而修复此警告。这是一种方法:

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 };
Run Code Online (Sandbox Code Playgroud)

采用自:Firebase 问题 1847#issuecomment-1041548028


小智 1

我们可能会面临同样类型的问题:(它与 Firebase 包相关。这是一个讨论潜在解决方案的线程。不幸的是,我认为 Firebase 方面还没有解决这个问题。

https://github.com/firebase/firebase-js-sdk/issues/1847