我得到的更具体的错误是:警告:道具类型失败:道具store
在Provider
中标记为必需,但其值为undefined
。
store.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
})
App.js:
import {store, persistor} from './src/store';
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<Layout />
</PersistGate>
</Provider>
任何帮助将不胜感激。
答案 0 :(得分:5)
在store.js
中,您不导出store
和persistor
,而是导出了一个函数,该函数返回带有store
和persistor
的对象。因此,您在import
中的App.js
语句实际上导入了两个不存在的命名导入。
您可以这样获取实例:
import factory from './src/store';
const {store, persistor} = factory();
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<Layout />
</PersistGate>
</Provider>