I'have a ReactJS event handler that need to change an array item, where the array is stored in component state. My code:
handleColumnResize = (index, width) => {
let formData = Object.assign({}, this.state.formData);
let columns = Object.assign({}, this.state.formData.columns);
columns[index].width = width;
formData.columns = columns;
this.setState({
formData: formData
});
if (this.props.onDataChange) this.props.onDataChange(formData);
};
I'm getting the following error:
TypeError: Cannot assign to read only property 'width' of object '#<Object>'
At the line: columns[index].width = width;
What is the correct way to change the content of the state array item?
OBS: My question is different of this post because if envolves changing an specific array item, no adding itens to a new array.