CellMeasurer --------------- High-order component that automatically measures a cell's contents by temporarily rendering it in a way that is not visible to the user. Specify a fixed width to measure dynamic height (or vice versa). This is an advanced component and has some limitations and performance considerations. [See below for more information](#limitations-and-performance-considerations). `CellMeasurer` can be used with `Grid`, `List`, and `Table` components. It is not intended to be used with the `Collection` component. ### Prop Types | Property | Type | Required? | Description | |:---|:---|:---:|:---| | cache | `CellMeasurerCache` | ✓ | Cache to be shared between `CellMeasurer` and its parent `Grid`. Learn more [here](#cellmeasurercache). | | children | Element or Function | ✓ | Either a React element as a child (eg `
`) or a function (eg. `({ measure }) => `). See [below](#using-cellmeasurer-with-images) for more detailed examples. | | columnIndex | number | ✓ | Index of column being measured (within the parent `Grid`) or 0 (if used within a `List` or `Table`). | | parent | `Grid` | ✓ | Reference to the parent `Grid`; this value is passed by `Grid` to the `cellRenderer` and should be passed along as-is. | | rowIndex | number | ✓ | Index of row being measured (within the parent `Grid`). | ### CellMeasurerCache The `CellMeasurerCache` stores `CellMeasurer` measurements and shares them with a parent `Grid`. It should be configured based on the type of measurements you need. It accepts the following parameters: ### Prop Types | Property | Type | Required? | Description | |:---|:---|:---:|:---| | defaultHeight | number | | Umeasured cells will initially report this height | | defaultWidth | number | | Umeasured cells will initially report this width | | fixedHeight | boolean | | Rendered cells will have a fixed height, dynamic width | | fixedWidth | boolean | | Rendered cells will have a fixed width, dynamic height | | minHeight | number | | Derived row height (of multiple cells) should not be less than this value | | minWidth | number | | Derived column width (of multiple cells) should not be less than this value | | keyMapper | KeyMapper | | Enables more intelligent mapping of a given column and row index to an item ID. This prevents a cell cache from being invalidated when its parent collection is modified. `(rowIndex: number, columnIndex: number) => any` | Note that while all of the individual parameters above are optional, you must supply at least some of them. `CellMeasurerCache` is not meant to measure cells that are both dynamic width _and_ height. It would be inefficient to do so since the size of a row (or column) is equal to the largest cell within that row. See [below](#limitations-and-performance-considerations) for more information. ### Examples ###### Grid This example shows a `Grid` with fixed row heights and dynamic column widths. For more examples check out the component [demo page](https://bvaughn.github.io/react-virtualized/#/components/CellMeasurer). ```jsx import React from 'react'; import { CellMeasurer, CellMeasurerCache, Grid } from 'react-virtualized'; // In this example, average cell width is assumed to be about 100px. // This value will be used for the initial `Grid` layout. // Cell measurements smaller than 75px should also be rounded up. // Height is not dynamic. const cache = new CellMeasurerCache({ defaultWidth: 100, minWidth: 75, fixedHeight: true }); function cellRenderer ({ columnIndex, key, parent, rowIndex, style }) { const content // Derive this from your data somehow return (