嗨,我正在尝试设置redux-坚持使用,但我无法让它工作。我得到以下错误:
TypeError:_store2.default不是一个学习更多index.js:12:29的函数
我现在是如何设置的:
store.js
import {applyMiddleware, createStore} from 'redux';
import {persistStore,persistCombineReducers} from 'redux-persist';
import storage from 'redux-persist/es/storage' // default: localStorage if web, AsyncStorage if react-native
import { logger } from 'redux-logger';
import thunk from 'redux-thunk';
import promise from 'redux-promise-middleware';
import reducer from './reducers'
const middleware = applyMiddleware(promise(), thunk, logger);
const config = {
key: 'root',
storage,
};
const reducers = persistCombineReducers(config, {reducer});
export const configureStore = () => {
const store = createStore(reducers, middleware);
const persistor = persistStore(store);
return { persistor, store };
};index.js
import React from 'react';
import ReactDOM from 'react-dom';
import {BrowserRouter} from 'react-router-dom';
import {Provider} from 'react-redux';
import Bootstrap from 'bootstrap/dist/css/bootstrap.css';
import './css/app.css';
import App from './containers/App';
import { PersistGate } from 'redux-persist/es/integration/react'
import configureStore from './store';
const { persistor, store } = configureStore()
ReactDOM.render(
<Provider store={store} >
<PersistGate persistor={persistor}>
<BrowserRouter>
<App/>
</BrowserRouter>
</PersistGate>
</Provider>,
document.getElementById('root')
);更新1
基于@azium的回应,我现在得到:
以上错误发生在组件中:在连接(App)(由路由创建)在路由(由withRouter(连接(应用程序)创建)在withRouter(连接(应用程序)),路由器(由BrowserRouter创建)中,在BrowserRouter(提供者中的PersistGate )中
当像这样从App.js调用它时:
@withRouter
@connect((store) => {
return {
isAuthenticated: store.auth.isAuthenticated,
};
})发布于 2017-12-27 00:59:43
因此,经过一些思考和社区的帮助,我设法把问题缩小到我的还原剂声明。我在index.js中用combineReducers声明还原剂,而redux持久化说它不应该是。
最终的index.js代码:
import user from './userReducer'
import auth from './authReducer'
export default ({
user, auth
})发布于 2017-12-21 19:37:25
如果要使用默认导出,则需要更改:
export const configureStore = () => {
const store = createStore(reducers, middleware);
const persistor = persistStore(store);
return { persistor, store };
};至:
export default () => {
const store = createStore(reducers, middleware);
const persistor = persistStore(store);
return { persistor, store };
};或者:
const configureStore = () => {
const store = createStore(reducers, middleware);
const persistor = persistStore(store);
return { persistor, store };
};
export default configureStore;或者如果您不想使用默认的导出更改:
import configureStore from './store';至:
import { configureStore } from './store';https://stackoverflow.com/questions/47929654
复制相似问题