0

I'm iterating through keys of a Maps object using a spread operator and would like to know how to derive the value from state.

 const [data, setData] = useState( 
    new Map( 
    Object.entries({
    datapoint1: "",
    datapoint2: "",
    datapoint3: "",
    datapoint4: ""
  })
  )
  );


{[...data.keys()].map((datapoint) => {
        return (
          <input
          className="inputboxes"
          id={datapoint}
          // value={} how to get value 
            key={datapoint}
            onChange={handleChange(datapoint)}
          />
        );

      }
      
      )}
Ibra
  • 912
  • 1
  • 12
  • 31

1 Answers1

0

I used the spread operator [...data] to work with an array format of the [key,value]of my state. I then used the get(key) method which returns a specified element that is associated with the key provided.

   value={[...data.get(datapoint)]}
Ibra
  • 912
  • 1
  • 12
  • 31