javascript - 为什么我在 React Redux reducer 中收到有关合成事件的警告?

标签 javascript reactjs redux lodash 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 设置为硬编码字符串。因此,问题似乎在于尝试在 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/

相关文章:

javascript - 使用 Safari 浏览器调试 Firebreath 代码

javascript - Redux 异步中间件操作没有 api 调用所需的现有状态

reactjs - 如何正确调用useFetch函数?

reactjs - Jest : Cannot read property 'secondary' of undefined - after MUI upgrade from V4 toV5

javascript - TweenMax 无法正确初始化 : "Uncaught Cannot tween a null target."

javascript - 对 OnSubmit 感到困惑

javascript - React 仅重新渲染网格中更改的元素

javascript - 通过多个参数对 oberservableArray 进行排序

javascript - 是否无法使用arguments 属性设置尚未提供的参数

javascript - JS 类 : avoiding manually assigning class variables