I have a state object with a nested array of objects called "axisLabels".
If the user is to enter anything into the input, I want to check if there is a comma (comma separated) within event.target.value of the input to update the second object within the array.
How is this possible?
My current function code updates both.
State obj:
selectedTemplateData: {
axisLabels: ['Option 1', 'Option 2']
}
function to update array:
axisChange(event) {
event.persist();
this.setState(prevState => ({
selectedTemplateData: {
...prevState.selectedTemplateData,
Axislables: [event.target.value, event.target.value]
}
}))
}
Usage:
<input type="text" onChange={(event) => this.axisChange(event)} />
if (event.target.value.indexOf(',') > -1) { event.target.value.split(',') }