gpt4 book ai didi

reactjs - 无法读取未定义的属性 'subscribe'-Redux Persist

转载 作者:行者123 更新时间:2023-12-05 08:54:01 24 4
gpt4 key购买 nike

我得到的更具体的错误是:警告: Prop 类型失败: Prop storeProvider 中被标记为必需,但它的值为 未定义

商店.js

const initialState = {};

const storage = createSensitiveStorage({
keychainService: "myKeychain",
sharedPreferencesName: "mySharedPrefs"
});

const config = {
key: "root",
storage,
};

const middleware = [thunk];

const reducer = persistCombineReducers(config, rootReducer);

export default () => {
let store = createStore(
reducer,
initialState,
compose(applyMiddleware(...middleware))
);
let persistor = persistStore(store);

return { store, persistor }
}

reducer 的 index.js:

export default combineReducers({
profile: profileReducer,
auth: authReducer,
photoSlider,
trip: tripReducer,
moment: momentReducer
})

应用程序.js:

import {store, persistor} from './src/store';

<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<Layout />
</PersistGate>
</Provider>

如有任何帮助,我们将不胜感激。

最佳答案

store.js 中,您不导出 storepersistor,而是导出一个返回对象的函数 >storepersistor。因此,您在 App.js 中的 import 语句实际上导入了两个不存在的命名导入

您可以这样获取您的实例:

import factory from './src/store';

const {store, persistor} = factory();

<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<Layout />
</PersistGate>
</Provider>

关于reactjs - 无法读取未定义的属性 'subscribe'-Redux Persist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51509298/

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