I have a form with onChange, in the onChange function I need to save values.
const [choosenVar, setChoosenVar] = useState([
{
posto1: { name: '', value: '' },
},
{
posto2: { name: '', value: '' },
},
{
posto3: { name: '', value: '' },
},
{
posto4: { name: '', value: '' },
},
{
posto5: { name: '', value: '' },
},
{
posto6: { name: '', value: '' },
},
]);
const onChange = event => {
const { name, value, id } = event.target;
// setchoosenVar({ ...choosenVar, [`posto${id}.nome`]: value });
const newArr = [...choosenVar];
};
Now my problem is for every "id" on event.target I should save the name and value in posto"id", How can I do??
Example:
const onChange = event => {
const { name, value, id } = event.target;
// name: "Application", value: "appSett", id: "1"
// in this case I should take: choosenVar.posto1 and set choosenVar.posto1.name = name, choosenVar.posto1.value= value.
};