2017-04-21 36 views
0

還原getState方法不可用。我是否需要任何中間件來達到預期的效果?以下是代碼無法訪問非反應組件上的商店

const configureStore = (initialState = {}) => { 
    return createStore(
    rootReducer, 
    initialState, 
    applyMiddleware(...middleware), 
); 
}; 

export default configureStore; 

util.js中

import store from '../../store'; 

store.getState() 

// _store2.default.getState is not a function 

回答

3

你是返回一個函數,而不是你的店。看起來你已經與商店混合了減速器。你想要的是:

const store = createStore(
    rootReducer, 
    initialState, 
    applyMiddleware(...middleware), 
); 


export default store; 
0

看起來像你打算在某些時候初始化商店。

我不知道要如何佈置你的應用程序,但

// index.js 

import configureStore from 'store'; 

export const store = configureStore({ ... someInitialState }); 

然後

// util.js 

import store from 'index'; 

// use store 

我不認爲這是最好的解決辦法 - 而不是出口的商店初始化從store,只需初始化商店並導出商店。