redux saga无法读取属性getState的undefined

时间:2016-11-21 10:44:45

标签: javascript reactjs redux redux-saga

我正在尝试使用saga中间件和异步操作建立一个react redux存储,以及react-router-redux和selectors。

对于某些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 个答案:

答案 0 :(得分:0)

你以错误的方式应用saga中间件。看看example sagaMiddlewate没有任何参数。

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