简体   繁体   English

为什么我在 React Redux 减速器中收到关于合成事件的警告?

[英]Why am I getting a warning about synthetic events in my React Redux reducer?

I'm trying to do this in a 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;

I've tried several variations and they all fail with;我尝试了几种变体,但都失败了;

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.

unless I remove newItem._rev = match.rev or set match to be a hard-coded string.除非我删除newItem._rev = match.rev或将match设置为硬编码字符串。 So it seems like the problem is with trying to use lodash's find inside of Array.map in a reducer, but I don't understand why that's a problem.所以似乎问题在于尝试在减速器中的Array.map中使用 lodash 的find ,但我不明白为什么这是一个问题。 I'm not consciously doing anything with events, so I'm having a hard time working around it to find a solution.我没有有意识地对事件做任何事情,所以我很难找到解决方案。

Edit: in case it's relevant, here's how I dispatch the action;编辑:如果它是相关的,这里是我如何分派动作;

return syncChangedItemsToDB(itemsChanged).then((resp) => {
  dispatch({type: actions.DATA_RETURNED, resp});
});

Does anyone know what's causing this warning and how I can work around it?有谁知道是什么导致了这个警告以及我如何解决它?

If I use Object.assign to copy the results of lodash's find , things seem to work with no problem, so this code works.如果我使用Object.assign复制 lodash 的find的结果,事情似乎没有问题,所以这段代码有效。 I'm still not sure why that's necessary, so any explanation would be appreciated.我仍然不确定为什么这是必要的,所以任何解释都将不胜感激。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM