I am trying to set up a cancel button that will revert all of my ref objects to their defaultValue. This property is nested within each element of the array in the item.state.defaultValue.
I am trying the code below:
My state of refs :
refs: Array<EditableText | null>;
The Editable text component
<EditableText
disabled={!this.state.editingDesc}
multiline={true}
maxLines={10}
defaultValue={description}
ref={input =>
(this.state.refs[index + 1] = input)
}
/>
public handleCancelBtn = () => {
const oldRefs = [...this.state.refs];
const newRefs = oldRefs.map(ref => {
if (ref != null) {
const newRef = Object.assign({}, ref);
const newState = Object.assign({}, ref.state, {
lastValue: ref.props.defaultValue,
value: ref.props.defaultValue
});
newRef.state = newState;
return newRef;
}
return null;
});
this.setState({
editingDesc: false,
refs: newRefs
});
}
It seems that my state is not updating. I believe this is because of the nested change of the property. I can find examples for one object nesting, but not how to do this for an array of objects. Thank you for any and all help