2016-11-21 29 views
0

我正在尝试设置一个具有传奇中间件和异步操作以及react-router-redux和选择器的reactx store。REDX传奇无法读取属性getState的undefined

对于某些sagamiddleware无法读取未定义的属性getState。我不知道为什么。

我的顶层目录结构为:

./src/app.js 
./src/sagas/index.js and imported sagas into this file 
./src/Containers/App/actions.js constants.js appReducer.js selectors.js 
./src/Containers/App/toplevelcomponenthere 

app.js

import sagas from './sagas'; 
import createReducer from './reducers.js'; 

const sagaMiddleware = createSagaMiddleware(); 
const createStoreWithMiddleware = applyMiddleware(reduxRouterMiddleware, 
sagaMiddleware(...sagas))(createStore); 

const store = createStoreWithMiddleware(createReducer); 
const reduxRouterMiddleware = syncHistoryWithStore(browserHistory) 

//add selectors and history 
import { selectLocationState } from './Containers/App/selectors'; 
const history = syncHistoryWithStore(browserHistory, store, { 
    selectLocationState: selectLocationState(), 
}); 

class Base extends Component { 
    render() { 
    return (
    <Provider store={store}> 
    {children} 
    </Provider> 
    ) 
    } 
} 
+1

你能不能用'getState' –

+0

@KevinKloet休息的getState内部添加代码终极版,传奇里面看到这里 https://github.com/yelouafi/redux-saga/blob/4ec433410c60eb1675ae786181651454fe766ddd/dist/redux-saga .js 代码行1898 – mibbit

回答

0

应用传奇中间件走错了路。看看examplesagaMiddlewate不带任何参数。

在创建商店后,您必须将root saga传递给store.runSaga函数,如here。这就是根本传奇 - 单个功能,例如fork你想使用的其他传说。我认为从./sagas导入的sagas不是一个单一的函数,因为您已经应用了扩展运算符。