I try to map an objects properties names and values to produce input fragments. While the mapping works for the initial input values it doesnt work to iterate through the properties names to call their state hooks.
I tried many approaches like;
Object.entries(hurdleRates).map(([key, value]) => {...
})`
OR
Object.keys(hurdleRates).map(function(key) {...
})`
Please Help! Thanks!
import React, { useState } from "react";
const RateSettings = () => {
const [hurdleRates, sethurdleRates] = useState({
bcLombard: 0.1,
bcOtherSecured: 0.2,
bcUnsecured: 0.3
});
return (
<div>
{Object.keys(hurdleRates).map(function(key) {
return (
<input
value={hurdleRates[key]}
onChange={e => sethurdleRates({ key: e.target.value })}
></input>
);
})}
</div>
);
};
export default RateSettings;
As an Outcome I expect three input tags generating three input boxes. In the code each should look like the following first one;
<input value=0.1 onChange{e => sethurdleRates({bcLombard : e.target.value})}> </input>