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')
);
文件夹src包含index.js和store.js
显示消息Uncaught TypeError:(0,_ store.configureStore)不是F12时的函数
帮助我谢谢
答案 0 :(得分:3)
2019年3月11日编辑:
这个答案可能不再适用。请参阅以下评论中的讨论,了解为什么以及实际解决方案应该是什么。
您从模块中导出单个函数,因此导入应为:
import configureStore from './store';
你会用
import {configureStore} from './store';
如果您的导出看起来像
export default {
configureStore: function(initialState) {
return createStoreWithMiddleware(rootReducer, initialState);
}
}