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. 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. 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. 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;
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.