【发布时间】:2020-02-23 17:45:31
【问题描述】:
我刚刚使用redux-persist@6.0.0 开始了一个新的 Managed Expo React Native 项目(Expo SDK 35,React Native 0.5.9),但是甚至一个新的带有 redux/redux-persist 的 expo 项目目前也在抛出以下错误。
使用来自react-native的AsyncStorage,
我们得到错误:
redux-persist: config.storage 是必需的。尝试使用提供的存储引擎之一
import storage from 'redux-persist/lib/storage'
使用来自@react-native-community/async-storage的AsyncStorage,
我们得到错误:
[@RNC/AsyncStorage]: NativeModule: AsyncStorage 为空。
使用来自redux-persist/lib/storage的storage,
我们得到错误:
console.error:“redux-persist 未能创建同步存储。回退到 noop 存储。”
问题:我们如何在不弹出的情况下解决这个问题?谢谢!
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);
【问题讨论】:
-
您能告诉我们您是如何使用
@react-native-community/async-storage声明您的persistConfig的吗? -
@Neeko 我已更新问题(已注释掉)以回答您的问题。谢谢!
-
您是在两个设备上还是在 iOS 上都遇到此问题?
-
@Neeko iOS。目前没有可用于测试的安卓设备。
标签: reactjs react-native expo asyncstorage redux-persist