【发布时间】:2016-05-04 06:53:32
【问题描述】:
我有一个这样的代码 sn-p
<Table selectable onRowSelection={this.onRecordSelected} bodyStyle={tableBodyStyle}>
<TableBody deselectOnClickaway={false} showRowHover displayRowCheckbox={false}>
{this.props.taskRecords.map((row, index) => (
<TableRow key={row.get('id')} selected={this.state.selectedRecordRowId === index}>
<TableRowColumn>{row.getIn(['task', 'name'])}</TableRowColumn>
<TableRowColumn>{row.getIn(['task', 'description'])}</TableRowColumn>
<TableRowColumn>{row.get('status')}</TableRowColumn>
<TableRowColumn>{row.get('log')}</TableRowColumn>
</TableRow>
))}
</TableBody>
</Table>
我查看了TableRow和TableRowColumn的源代码,发现它们没有实现shouldComponentUpdate方法。我知道当任何状态发生变化时它们会被重新渲染。
我尝试使用recompose 库中的pure 函数将这些净化为组件。
const TableRow = pure(require('material-ui/lib/table/table-row'));
const TableRowColumn = pure(require('material-ui/lib/table/table-row-column'));
据我了解,如果props 不改变,纯化后的组件将不再重新渲染。在这种情况下,所有的 props 要么是来自 Immutable.js 的不可变对象,要么是函数。
当我选择任何行时,有什么方法可以防止它重新呈现?
提前谢谢你。
【问题讨论】:
标签: javascript reactjs material-ui