I have an react state with objects/array that is filled, but also then later I want to edit text inputs and edit the related fields on object also, i found no solutions until now.
So this is my state for example:
const [data, setData] = useState({
working_hours: [
{
id: 1,
description: 'Random Text',
price: 100,
},
{
id: 2,
description: 'Text Random',
price: 100,
},
]
});
Here is my Jsx:
{data.working_hours.map(item =>
<>
<input type={text} value={item.description}
onChange={(e) => handleChange(e)} />
<input type={text} value={item.price}
onChange={(e) => handleChange(e)} />
</>
)}
Here is what I tried:
function handleChange(e){
const value = e.target.value;
setData({...data, [...data.working_hours, e.target.value]})
}