Unable to export generator functions

南笙酒味 提交于 2019-12-06 15:43:28

Can anyone tell me why the above code is invalid?

This is well-known issue of regenerator-transform babel plugin, which is commonly used for transpiling code with sagas. That issue also affects async functions, because they are implemented by regenerator-transform mechanism too.

export default function* () {
    yield takeEvery('DO_SOMETHING_REQUEST', andDoThisFunc);
}

After transforming that code , there can be two issues. First is omitting inclusion of regenerator-runtime dependency, which is mandatory. Second is function hoisting, so if occurrence order matters, it should be specified implicitly.

Correct solution is:

import 'regenerator-runtime';
const mySaga = function* () {
    yield takeEvery('DO_SOMETHING_REQUEST', andDoThisFunc);
}
export default mySaga;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!