redux-saga select()返回undefined

时间:2017-09-28 18:26:19

标签: javascript reactjs redux redux-saga

我无法让redux-saga / effects选择方法按照宣传的方式工作。我尝试了很多尝试,这是我最简单的尝试使用select的一个例子,我期望它返回我的状态但是返回undefined。

Saga.js:

export function* selectTest() {
  const temp = yield* select();
  console.log('select returns: ', temp);
  return temp;
}

export default [
  selectTest,
]
routes.js中的

(我正在使用react-boilerplate)

return [
 {
    path,
    name: 'home',
    getComponent(nextState, cb) {
      const importModules = Promise.all([
          System.import('containers/UiComponentsHomePage/sagas')
          System.import('containers/UiComponentsHomePage'),
      ]);

    const renderRoute = loadModule(cb);

    importModules.then(([saga, component]) => {
      injectSagas(saga.default);
      renderRoute(component);
    });

    importModules.catch(errorLoading);
   },
  }
 ];

我希望看到我的状态在select返回后打印出来,但它返回undefined。我可以看到我的状态设置正确,其他组件可以使用它。

为什么select()不返回状态?

2 个答案:

答案 0 :(得分:2)

请勿使用yield *,只需使用yield select()即可。 yield *用于子生成器集成。

答案 1 :(得分:0)

您需要传入一个实际的选择器功能。最简单的例子是:

function* selectAndPrintState() {
    const selectAllState = (state) => state;

    const allState = yield select(selectAllState);
    console.log(allState);
}
相关问题