gpt4 book ai didi

reactjs - Expo React Native App + Redux-Persist : AsyncStorage Problem

转载 作者:行者123 更新时间:2023-12-04 01:00:30 24 4
gpt4 key购买 nike

我刚刚使用 redux-persist@6.0.0 启动了一个新的 Managed Expo React Native 项目(Expo SDK 35,React Native 0.5.9)但即使是一个带有 redux/redux-persist 的新世博会项目目前也会抛出以下错误。

使用 AsyncStorage来自 react-native ,

我们得到错误:

redux-persist: config.storage is required. Try using one of the provided storage engines import storage from 'redux-persist/lib/storage'



使用 AsyncStorage来自 @react-native-community/async-storage ,

我们得到错误:

[@RNC/AsyncStorage]: NativeModule: AsyncStorage is null.



使用 storage来自 redux-persist/lib/storage ,

我们得到错误:

console.error: "redux-persist failed to create sync storage. falling back to noop storage."



问题:我们如何在不弹出的情况下解决这个问题?谢谢!

redux-persist代码

注意:以前的尝试已被注释掉:
// Chose 1 of the 3 storages
// import { AsyncStorage } from "react-native";
// import AsyncStorage from '@react-native-community/async-storage';
import storage from 'redux-persist/lib/storage'

import { createMigrate, persistStore, persistReducer } from "redux-persist";
import reducer from "../reducers";

const persistConfig = {
key: 'root',
version: 0,
storage, // 'redux-persist/lib/storage'
}

// const persistConfig = {
// key: 'root',
// version: 0,
// AsyncStorage, // '@react-native-community/async-storage'
// }

const persistedReducer = persistReducer(persistConfig, reducer);

最佳答案

此导入用于 Web App:

import storage from 'redux-persist/lib/storage'

对于 React Native,您应该使用以下导入:
import AsyncStorage from '@react-native-community/async-storage';
import { createMigrate, persistStore, persistReducer } from "redux-persist";
import reducer from "../reducers";

const persistConfig = {
key: 'root',
version: 0,
//...
storage: AsyncStorage
}

const persistedReducer = persistReducer(persistConfig, reducer);

关于reactjs - Expo React Native App + Redux-Persist : AsyncStorage Problem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58591279/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com