已使用expo安装安装了@react-native-async-storage/async-storage,但损坏警告不会消失

dfddblmv  于 2023-02-16  发布在  React
关注(0)|答案(2)|浏览(160)

我在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"
  }
62lalag4

62lalag41#

尽管这是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 };

采用自:Firebase问题1847 #问题注解-1041548028

mcdcgff0

mcdcgff02#

我们可能会面临同样类型的问题:(这是有关Firebase包。这里是一个线程,讨论潜在的解决方案。我不认为它是固定在Firebase的一方不幸的是...
https://github.com/firebase/firebase-js-sdk/issues/1847

相关问题