I have simple form where onChange value is updated as typed.
Example when type 12, only 1 is saved in the state and when type second time 123 only 12 is stored.
useState :
const [costsFormValues, setCostsFormValues] = useState({});
Function
const handleCostInputValues = (event, index) => {
setCostsFormValues({
...costsFormValues,
[event.target.name]: [event.target.value],
});
console.log(costsFormValues) //prints only 1 instead of 12
}
Form
<Form.Control type="number" onChange={e => handleCostInputValues(e, i)} />