I am using the
props.setSelectValue((prevState: any) => ([...prevState, {control: props.data.control, value:itemValue}]))
to update and array of objects, but it is appending value to a previous object and I would like just to update when the key is already in the object. How can I do it?
You could set the values to undefined if they aren't defined in prevState
props.setSelectValue((prevState: any) => ([...prevState, {
control: prevState.control ? props.data.control : undefined,
value: prevState.value ? itemValue : undefined
}]))