feat: DataTable component optimization

This commit is contained in:
Sérgio Salgado 2021-01-20 14:20:30 +00:00 committed by Josh Harvey
parent 5d868af9e7
commit 553736fb84

View file

@ -110,11 +110,12 @@ const DataTable = ({
const classes = useStyles({ width }) const classes = useStyles({ width })
const expandRow = id => { const expandRow = id => {
cache.clear(id)
setExpanded(id === expanded ? null : id) setExpanded(id === expanded ? null : id)
} }
const cache = new CellMeasurerCache({ const cache = new CellMeasurerCache({
defaultHeight: 62, defaultHeight: 58,
fixedWidth: true fixedWidth: true
}) })
@ -126,7 +127,8 @@ const DataTable = ({
key={key} key={key}
parent={parent} parent={parent}
rowIndex={index}> rowIndex={index}>
<div style={style}> {({ registerChild }) => (
<div ref={registerChild} style={style}>
<Row <Row
width={width} width={width}
id={index} id={index}
@ -140,6 +142,7 @@ const DataTable = ({
onClick={onClick} onClick={onClick}
/> />
</div> </div>
)}
</CellMeasurer> </CellMeasurer>
) )
} }
@ -173,7 +176,7 @@ const DataTable = ({
rowCount={data.length} rowCount={data.length}
rowHeight={cache.rowHeight} rowHeight={cache.rowHeight}
rowRenderer={rowRenderer} rowRenderer={rowRenderer}
overscanRowCount={50} overscanRowCount={5}
deferredMeasurementCache={cache} deferredMeasurementCache={cache}
/> />
)} )}