分配的来源之一在原型链上有一个可枚举的密钥-替换数组中的对象时

时间:2019-02-04 12:11:04

标签: arrays react-native object replace immutability-helper

我只是使用immutability helper在特定索引处更新数组中的对象。

import update from 'immutability-helper';
const { updateData, surveysData } = this.state;
      surveysData.map((item, i) => {
        if (item.id === updateData.id) {
          const updatedData = update(surveysData, { $splice: [[i, 1, updateData]] });
          this.setState({ surveysData: updatedData });
        }
      });

此处updateData是{object}。和 surveyData是[array]

我也尝试使用$set,但仍然遇到相同的错误

surveysData.map((item, i) => {
        if (item.id === updateData.id) {
          this.setState({ surveysData: update(surveysData, { [i]: { $set: updateData } }) });
        }
      });

screenshot

0 个答案:

没有答案