By default, React re-displays everything, but if there are performance issues, you can use the shouldComponentUpdate function to determine which parts of the component tree to exclude updates.
In your example, there is only one row that can be updated immediately, so if we start to track which row has occurred, we can make sure that only this row is updated. First, we must introduce a new component, which is where we can place our hook.
var Row = React.createClass({ shouldComponentUpdate: function(nextProps) { return nextProps.mustUpdate; }, render: function() { return <tr>{this.props.children}</tr>; } });
Then we can use it as
items.push( <Row key={r} mustUpdate={this.state.lastUpdatedRow === r}> {cols} </Row>);
In addition, it seems that the waste also revises all of these cells, so we can introduce another component that wraps the table cells.
var Cell = React.createClass({ shouldComponentUpdate: function(nextProps) { return this.props.selected !== nextProps.selected; }, render: function() { var props = this.props; return ( <td onClick={props.onClick.bind(null, props.col, props.row)} className={props.selected ? 'c' : ''}> </td> ); } });
This should give you significant performance improvements with updates. If it is not good enough for your specific problem, it is possible that React is not ideal for your use case. In any case, this is the essence of optimizing React programs, you break components into smaller components and make sure that only the parts that actually changed the update.
Heap source share