首页 > 代码库 > [React] Create an Auto Resizing Virtualized List with react-virtualized
[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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。