How to measure the height of rows in a victorious list

I am a little sure how to achieve dynamic list heights using react-virtualized .

I have a component as follows:

import { List } from 'react-virtualized';
<List
    height={400}
    rowCount={_.size(messages)}
    rowHeight={(index) => {
        return 100; // This needs to measure the dom.
    }}
    rowRenderer={({ key, index, style }) => <Message style={style} {...messages[index]} />}}
    width={300}
/>

I examined the use of CellMeasurer according to the docs that say it can be used with the List component, but I have no idea how this example really works ...

I also tried to figure out how this was achieved in the demo code but also reached a dead end.

Can someone please help me in how I will measure the DOM in order to dynamically receive each position.

+4
source share
1

, , . , . , :

import { CellMeasurer, List } from 'react-virtualized';

function renderList (listProps) {
  return (
    <CellMeasurer
      cellRenderer={
        // CellMeasurer expects to work with a Grid
        // But your rowRenderer was written for a List
        // The only difference is the named parameter they
        // So map the Grid params (eg rowIndex) to List params (eg index)
        ({ rowIndex, ...rest }) => listProps.cellRenderer({ index: rowIndex, ...rest })
      }
      columnCount={1}
      rowCount={listProps.rowCount}
      width={listProps.width}
    >
      {({ getRowHeight, setRef }) => (
        <List
          {...listProps}
          ref={setRef}
          rowHeight={getRowHeight}
        />
      )}
    </CellMeasurer>
  )
}

, , .

+7

Source: https://habr.com/ru/post/1655230/


All Articles