[英]Why am I getting a warning about synthetic events in my React Redux 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
设置为硬编码字符串。 所以似乎问题在于尝试在减速器中的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;
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.