[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;
时间: 2024-10-16 07:06:50

[React] Create an Auto Resizing Virtualized List with react-virtualized的相关文章

react看这篇就够了(react+webpack+redux+reactRouter+sass)

本帖将对一下内容进行分享: 1.webpack环境搭建: 2.如何使用react-router: 3.引入sass预编译: 4.react 性能优化方案: 5.redux结合react使用: 6.fetch使用: 7.项目目录结构: 一.webpack配置,代码如下: 1.在根目录下新建一个webpack.config.js,这个为开发环境的webpack配置:因为得区分开发跟生产环境,所以还得新建一个webpack.production.config.js作为生产环境使用的配置文档, webp

【react自制全家桶】一、Webstrom+React+Ant Design+echarts搭建react项目

前言 一.React是Facebook推出的一个前端框架,之前被用于著名的社交媒体Instagram中,后来由于取得了不错的反响,于是Facebook决定将其开源.出身名门的React也不负众望,成功成为当前最火热的三大前端框架之一.相比于Angular,React更加轻量.而相对于另一个轻量级前端框架Vue来说,React虽然学习和使用起来难度稍微大一些,但是React的社区相对来说人气更旺,而且在移动端的开发上面,大名鼎鼎的React Native更是尽显优势,在代码性能上要好过Vue框架.

学习React前端框架,报错 &#39;React&#39; must be in scope when using JSX react/react-in-jsx-scope

问题 import react from 'react'  改成  import React from 'react'   小写 react  改成 React 学习React前端框架,报错 'React' must be in scope when using JSX react/react-in-jsx-scope 原文地址:https://www.cnblogs.com/BensonHai/p/9952156.html

react入门系列之todolist代码优化(使用react 新特性,es6语法)

代码优化 1 /** 2 - 今天我们通过es6语法,以及react新特性来优化我们的todo-list 3 - 顺带解决上个版本的key报错问题 4 */ 使用es6的解构赋值优化代码 1 /** 2 - 当我们需要一个对象某个属性的时候,我们可以使用解构赋值,这样在后续的代码就不需要通过原对象不停调用属性去获取了 3 - const { index } = this.props -----> 这就是解构赋值,在后续同一作用域使用this.props.index的时候直接使用index就可以了

react常见组件问题Can&#39;t perform a React state update on an unmounted component

在些react组件的时候,会有这个警告 Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method” 这是因为在写一

[React] Create a Virtualized List with Auto Sizing Cells using react-virtualized and CellMeasurer

In this lesson we'll use CellMeasurer and CellMeasurerCache to automatically calculate and cache the height of a row. This will allow us to remove the predefined rowHeight on list and allow for dynamically sized rows. import React, {Component} from '

[React] Create component variations in React with styled-components and &quot;extend&quot;

In this lesson, we extend the styles of a base button component to create multiple variations of buttons, using "extend". We can then modify the base styles in one place, and have all button types updated. import React from "react"; im

[React] Create &amp; Deploy a Universal React App using Zeit Next

In this lesson, we'll use next to create a universal React application with no configuration. We'll create page components that will render on the server if accessed directly, but function as you would expect in the client. We'll use the routing capa

【REACT NATIVE 系列教程之十二】REACT NATIVE(JS/ES)与IOS(OBJECT-C)交互通信

一用到跨平台的引擎必然要有引擎与各平台原生进行交互通信的需要.那么Himi先讲解React Native与iOS之间的通信交互. 本篇主要分为两部分讲解:(关于其中讲解的OC语法等不介绍,不懂的请自行学习) 1. React Native 访问iOS 2. iOS访问React Native     一:React Native 访问iOS 1. 我们想要JS调用OC函数,就要实现一个"RCTBridgeModule"协议的Objective-C类 所以首先我们先创建一个oc新类,