score:0

Accepted answer

you aren't using the map function correctly. array::map returns a new array, the values of the original array mapped to new values.

update handlefeeandinch simply be the map callback, returning a new value into a new array, then set state with that array.

handlefeetandinch = (key, namevalue, value) => {
  let realfeet = (value * 0.3937) / 12;
  let feet = math.floor(realfeet);
  let inches = math.round((realfeet - feet) * 12);
  let updatedvalue = `${feet}'${inches}"`;

  // return new measurement value
  return {
    name: namevalue,
    value: updatedvalue
  };
};

handleunitchange = () => {
  if (this.state.iscm) {
    // reset state
  } else {
    // get array of new measurements
    const newmeasurements = this.state.measurements.map((measurement, key) =>
      measurement.algo === 1
        ? this.handlefeetandinch(key, measurement.name, measurement.value)
        : this.handleinches(key, measurement.name, measurement.value)
    );
    this.setstate(prevstate => ({
      measurements: newmeasurements
    }));
    this.setstate(prevstate => ({
      iscm: !prevstate.iscm
    }));
  }
};

Related Query

More Query from same tag