I have a ReactJS HTML table component and I update its content (cell values) with the setState
method. Here is the basic code:
var Cell = React.createClass({
render: function () {
return (<td>{this.props.cellValue}</td>);
}
});
var Row = React.createClass({
render: function () {
return (<tr>{this.props.row}</tr>);
}
});
var Table = React.createClass({
getInitialState: function() {
return {
data: this.props.data
};
},
render: function () {
return (
<table>
{
this.state.data.map(function(row) {
var r = row.map(function(cell) {
return <Cell cellValue={cell}/>;
});
return (<Row row={r}/>);
})
}
</table>
);
}});
You would use it like this:
var initialData = [[1,2,3],[4,5,6],[7,8,9]];
var table = React.renderComponent(
<Table data={initialData} />,
document.getElementById('table')
);
This is working most of the time. I can change the data by doing this (somewhere in a function or whatever):
var newData = [[1,2,3],[4,5,6],[7,8,9],[10,11,12]];
table.setState({data : newData});
As you can see, it adds one row to the end of the table. However, if I try to set the initial data after this update or in any way shorten the number of rows by setting data
to a smaller array (e. g. [[1, 2, 3], [4, 5, 6]]
which should remove the last row):
table.setState({data : initialData});
I get this error:
TypeError: updatedChildren[j] is undefined updatedChildren[j].parentNode.removeChild(updatedChildren[j]);
Where does it come from?