Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React from 'react';
- import { CellMeasurer, CellMeasurerCache, List } from 'react-virtualized';
- // In this example, average cell height is assumed to be about 50px.
- // This value will be used for the initial `Grid` layout.
- // Width is not dynamic.
- const cache = new CellMeasurerCache({
- defaultHeight: 50,
- fixedWidth: true
- });
- function rowRenderer ({ index, isScrolling, key, parent, style }) {
- const source // This comes from your list data
- return (
- <CellMeasurer
- cache={cache}
- columnIndex={0}
- key={key}
- parent={parent}
- rowIndex={index}
- >
- {({ measure, registerChild }) => (
- // 'style' attribute required to position cell (within parent List)
- <div ref={registerChild} style={style}>
- <img
- onLoad={measure}
- src={source}
- />
- </div>
- )}
- </CellMeasurer>
- );
- }
- function renderList (props) {
- return (
- <List
- {...props}
- deferredMeasurementCache={cache}
- rowHeight={cache.rowHeight}
- rowRenderer={rowRenderer}
- />
- );
- }
Advertisement
Add Comment
Please, Sign In to add comment