Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native 如何使用React Native的收益率内部映射_React Native_Redux Saga - Fatal编程技术网

React native 如何使用React Native的收益率内部映射

React native 如何使用React Native的收益率内部映射,react-native,redux-saga,React Native,Redux Saga,我的目标是在map中执行分叉函数 以下是我尝试过的: function* doSomethingWithItem(item) {} yield all(items.map(item => { // ... some item checking return fork(doSomethingWithItem, item); })); 还尝试使用yield fork(),但出现错误“yield是一个保留字…” 未调用doSomethingWithItem() 感

我的目标是在
map
中执行分叉函数

以下是我尝试过的:

  function* doSomethingWithItem(item) {}

  yield all(items.map(item => {
    // ... some item checking
    return fork(doSomethingWithItem, item);
  }));
还尝试使用
yield fork()
,但出现错误“yield是一个保留字…”

未调用doSomethingWithItem()


感谢您的帮助。

由于
map
使用lambda函数,因此您实际上无法直接从中产生一些结果

yield all
是一种正确的方法,但是与
fork
不同,
call
效果在这种情况下看起来更合适,因为它是阻塞的,因此保留了项目处理顺序(如果这很重要):


我还检查了您的代码,
doSomethingWithItem
在我的环境中工作。尝试用Try/catch包装您的代码,可能您有一个错误,使saga停止。

是的,在
catch
删除错误后,错误是无关的。谢谢~
function * doSomethingWithItem ( item ) {
  console.log('doSomethingWithItem', item)
}

function * doSomethingWithAllItems ( items ) {
  console.log('doSomethingWithAllItems')
  yield all(items.map(item =>
    call(doSomethingWithItem, item),
  ))
  console.log('done doSomethingWithAllItems')
}

function * mySaga () {
  yield call(doSomethingWithAllItems, [1, 2, 3, 4, 5])
}