[React] Create an Auto Resizing Virtualized List with react-virtualized

In this lesson we'll show how to use the AutoSizer component from react-virtualized to automatically measure the width/height of our content area. We'll then use theList component to render our set of data as a virtualized list into the DOM using windowing.

Install:

npm install --save react-vistualized
import React, {Component} from 'react';
import {AutoSizer, List} from 'react-virtualized';

const ScreenInfo = ({width, height}) => (<span> {width} height: {height}</span>);

class App extends Component {

    renderRow = ({key, isScrolling, style, index}) => {
        return (
            <div style={style} key={key}>
                name: {this.props.data[index].name}
                email: {this.props.data[index].email}
            </div>
        );
    };

    render() {
        return (
            <AutoSizer>
                {({width, height}) => {
                    return (
                        <div>
                            <ScreenInfo width={width} height={height}/>
                            <List
                                rowCount={this.props.data.length}
                                rowHeight={50}
                                rowRenderer={this.renderRow}
                                width={width}
                                height={height}
                            />

                        </div>
                    );
                }}
            </AutoSizer>
        );
    }
}

export default App;
原文地址:https://www.cnblogs.com/Answer1215/p/7083155.html