Uncaught TypeError: (0 , _store.configureStore) is not a function
Uncaught TypeError: (0 , _store.configureStore) is not a function
store.js
import {createStore, applyMiddleware} from 'redux';
import createLogger from 'redux-logger';
import rootReducer from './reducers/index';
const logger = createLogger();
const createStoreWithMiddleware = applyMiddleware(logger)(createStore);
export default function configureStore(initialState) {
return createStoreWithMiddleware(rootReducer, initialState);
}
index.js
import React from 'react';
import ReactDOM from 'react-dom';
import TrackList from './components/TrackList';
import {configureStore} from './store';
import * as actions from './actions';
const tracks = [
{
id: 1,
title: 'Title 1'
},
{
id: 2,
title: 'Title 2'
}
];
const store = configureStore();
store.dispatch(actions.setTracks(tracks));
ReactDOM.render(
<TrackList />,
document.getElementById('app')
);
文件夹源包含 index.js 和 store.js
显示消息 Uncaught TypeError: (0 , _store.configureStore) 在 F12
时不是一个函数
帮帮我谢谢
2019 年 3 月 11 日编辑:
这个答案可能不再有效。请参阅下面评论中的讨论,了解原因以及实际解决方案应该是什么。
您从模块中导出了一个函数,因此您的导入应该是:
import configureStore from './store';
你会用
import {configureStore} from './store';
如果您的导出看起来像
export default {
configureStore: function(initialState) {
return createStoreWithMiddleware(rootReducer, initialState);
}
}
store.js
import {createStore, applyMiddleware} from 'redux';
import createLogger from 'redux-logger';
import rootReducer from './reducers/index';
const logger = createLogger();
const createStoreWithMiddleware = applyMiddleware(logger)(createStore);
export default function configureStore(initialState) {
return createStoreWithMiddleware(rootReducer, initialState);
}
index.js
import React from 'react';
import ReactDOM from 'react-dom';
import TrackList from './components/TrackList';
import {configureStore} from './store';
import * as actions from './actions';
const tracks = [
{
id: 1,
title: 'Title 1'
},
{
id: 2,
title: 'Title 2'
}
];
const store = configureStore();
store.dispatch(actions.setTracks(tracks));
ReactDOM.render(
<TrackList />,
document.getElementById('app')
);
文件夹源包含 index.js 和 store.js
显示消息 Uncaught TypeError: (0 , _store.configureStore) 在 F12
时不是一个函数帮帮我谢谢
2019 年 3 月 11 日编辑:
这个答案可能不再有效。请参阅下面评论中的讨论,了解原因以及实际解决方案应该是什么。
您从模块中导出了一个函数,因此您的导入应该是:
import configureStore from './store';
你会用
import {configureStore} from './store';
如果您的导出看起来像
export default {
configureStore: function(initialState) {
return createStoreWithMiddleware(rootReducer, initialState);
}
}