This question already has answers here:
SyntaxError: Unexpected Identifier (Generators in ES6)
                                
                                    (2个答案)
                                
                        
                                2年前关闭。
            
                    
我在react-redux-saga项目中遇到此错误:


  语法错误:yield是保留字(66:16)




 function* broken(action) {
  props.forEach(prop => {
    const res = yield put(blah)
    // do stuff yada yada in here
  })
}

最佳答案

事实证明,内部函数也必须是一个生成器-但是that then causes, erm, problems。因此最好使用没有回调的标准循环。就像是:



function* working(action) {
  for (const prop of props) {
    const res = yield put(blah)
    // do stuff yada yada in here
  }
}

10-05 20:18