I have an array of objects. In that array, I want to update a single object, and in that object, I want to update only specific properties. I tried:
setRequiredFields(prevRequiredFields => ([
...prevRequiredFields, prevRequiredFields.find(x => x.name = field) ? {
isValid: isValid,
content: content,
isUnchanged: false
}
]));
But it didn't work. Required fileds is an array with the following structure:
[{
name: "Name",
isValid: false,
content: "",
isUnchanged: true,
tip: "Name cannot be empty",
isValidCondition: notEmptyRegex,
reportState: validateField
}]
What I'm trying to do here is to update only a isValid, content and isUnchanged of one specific object inside that array. How can I accomplish that?
.mapinstead then? Just dosetRequiredFields(prevRequiredFields.map(item => item.name === field ? {...item, isValid, content, isUnchanged: false} : item)