I have an object looking like this:
categories : [
{
name: "General Information",
rows: [
{
information1 : "",
information2 : "",
}
]
}
]
And I am displaying the rows content using a loop like this:
{formData?.categories?.map(c => (
<div>
{c.name}
{c.rows.map((row) => (
<div>
<input value={field.information1} />
<textarea value={field.information2}></textarea>
<button onClick={() => addRow(c.name)}>Add Row here</button>
</div>
))}
</div>
))}
When I press one of these buttons (that should add a row to rows array) the formData state does update, but the displayed data does not.
function addRow(category) {
const updatedFormData = formData
for (const cat of updatedFormData.categories) {
if (cat.name === category) {
cat.rows.push({
information1 : "test",
information2 : "this is a test"
})
}
}
setFormData(updatedFormData)
}