list with constant row height, but unknown ahead of time.
I have (I think) quite common use case - I want to render a list of rows, with a constant height and width, but I do not know the height (in px) ahead of time (since it is set in css). react-virtualized provides a high performance (but undocumented) solution to achieve this using the cell measurer. which can be used in the standard documented way:
<CellMeasurer
cache={cache}
columnIndex={columnIndex}
key={key}
parent={parent}
rowIndex={rowIndex}
>
<div
style={{
...style,
height: 35,
whiteSpace: 'nowrap'
}}
>
{content}
</div>
</CellMeasurer>
The problem here is that every row gets individually measured and this is slow. But we only want to measure one row - the first row - and set all following rows to this height. to do this, we can set up the cellmeasurercache like so - please note the keymapper field:
const cache = new CellMeasurerCache({ defaultHeight: 30, fixedWidth: true, keyMapper:() => 1 });
now all row measurements after the first one will hit the cache and we get a speedy solution.
Im raising this as an issue because I think this use case should be documented.
Nice solution. 😄
Please feel free to open a PR with suggested docs changes!