2016-09-18 144 views
2

store.js未捕獲的類型錯誤:(0,_store.configureStore)不是函數

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

幫我謝謝

回答

2

您從模塊導出一個單一的功能,讓你的進口應該是:

import configureStore from './store'; 

你會使用

import {configureStore} from './store'; 

如果你的出口看起來像

export default { 
    configureStore: function(initialState) { 
    return createStoreWithMiddleware(rootReducer, initialState); 
    } 
} 
+0

非常感謝你很多,我是新手REDX,再次感謝 –

+0

最終'出口默認{...'實際上不再工作。根據規格,您現在必須按名稱出口。導出應該是'export function configureStore(initialState){...}'。 – DDS

+1

@HieuBui請注意,這是一個與Redux無關的ES6問題。 – DDS

相關問題