I want to overwrite the array if the keys are the same. And push if keys are different.
From this:
const fieldData = [
{
"field_1": {
"value": "oldValue"
},
"field_2": {
"value": "oldValue"
}
}
];
const [data, setData] = useState(fieldData);
const pushData = (newData) => {
setData(current => [...current, newData]);
}
The result if the keys are the same:
{
"field_1": {
"value": "newValue"
},
"field_2": {
"value": "oldValue"
}
}
The result if the keys are diffrent:
{
"field_1": {
"value": "newValue"
},
"field_2": {
"value": "oldValue"
},
"field_3": {
"value": "newValue Field 3"
}
}