update particular object of features array

Viewed 78

I am struggling to update the particular object from features array and returning the whole object with the updated one. I could update the particular object but could not return the same whole object with the updated one. I am doing this using immutablejs. Here is my code

    case EDIT_FEATURE_SUCCESS: {
  return state
    .set('requesting', false)
    .set('response', action.response.data.message)
    .update('features', features =>
      state.get('features').map(feat => {
        return {
          ...feat,
          features: features.map(feature => {
            if (feature._id === action.response.data.featureObj._id) {
              return action.response.data.featureObj;
            } else return feature;
          })
        };
      })
    );
}

I need the following object

enter image description here

with the updated one but I am getting something like this

enter image description here

1 Answers
Related