score:0

Accepted answer
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