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

Posted Answer1215

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[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: {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;

 

以上是关于[React] Create an Auto Resizing Virtualized List with react-virtualized的主要内容,如果未能解决你的问题,请参考以下文章

关于React报Too many re-renders. React limits the number of renders to prevent an infinite错误的解决方案

在使用create-react-app创建项目时,控制台爆出这个错误 A template was not provided. This is likely because you're us

在使用create-react-app创建项目时,控制台爆出这个错误 A template was not provided. This is likely because you're us

1. Getting Started and Create an Android Client

react

create-react-app 自版本 4.0.1 起无法正常工作