我正在尝试在 reducer 中执行此操作;
case actions.DATA_RETURNED:
newState = Object.assign({}, state);
newState.status = 'complete';
if (resp) {
var newItems = newState.items.map(item => {
var newItem = Object.assign({}, item);
var match = _.find(resp, { id: item._id });
newItem._rev = match.rev;
return newItem;
});
}
break;
我尝试了几种变体,但都失败了;
warning.js:36 Warning: This synthetic event is reused for performance reasons. If you're seeing this, you're accessing the property cancelable on a released/nullified synthetic event. This is set to null. If you must keep the original synthetic event around, use event.persist(). See https://facebook.github.io/react/docs/events.html#event-pooling for more information.
除非我删除 newItem._rev = match.rev
或将 match
设置为硬编码字符串。因此,问题似乎在于尝试在 reducer 中的 Array.map
中使用 lodash 的 find
,但我不明白为什么这是个问题。我没有有意识地对事件做任何事情,所以我很难找到解决方案。
编辑:如果它是相关的,这里是我如何发送操作;
return syncChangedItemsToDB(itemsChanged).then((resp) => {
dispatch({type: actions.DATA_RETURNED, resp});
});
有谁知道导致此警告的原因以及我该如何解决?
最佳答案
如果我使用 Object.assign
复制 lodash 的 find
的结果,事情似乎没有问题,所以这段代码有效。我仍然不确定为什么这是必要的,所以任何解释将不胜感激。
newItems = newState.items.map(item => {
var match = Object.assign({}, _.find(resp, { id: item._id }));
if (match.rev) item._rev = match.rev;
return item;
});
关于javascript - 为什么我在 React Redux reducer 中收到有关合成事件的警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39768436/