[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';
import {AutoSizer, List, CellMeasurer, CellMeasurerCache} from 'react-virtualized';
const ScreenInfo = ({width, height}) => (<span>width: {width} height: {height}</span>);
class App extends Component {
constructor(props) {
super(props);
this.cache = new CellMeasurerCache({
fixedWidth: true,
defaultHeight: 50
});
}
renderRow = ({key, isScrolling, parent, style, index}) => {
return (
<CellMeasurer
key={key}
cache={this.cache}
parent={parent}
columnIndex={0}
rowIndex={index}
>
<div style={style} >
name: {this.props.data[index].name}
email: {this.props.data[index].email}
height: <div style={{height: `${this.props.data[index].randomHeight}px`}}>{this.props.data[index].randomHeight}px</div>
</div>
</CellMeasurer>
);
};
render() {
return (
<AutoSizer>
{({width, height}) => {
return (
<div>
<ScreenInfo width={width} height={height}/>
<List
rowCount={this.props.data.length}
deferredMeasurementCache={this.cache}
rowHeight={this.cache.rowHeight}
rowRenderer={this.renderRow}
width={width}
height={height}
/>
</div>
);
}}
</AutoSizer>
);
}
}
export default App;
[React] Create a Virtualized List with Auto Sizing Cells using react-virtualized and CellMeasurer的更多相关文章
- [React] Create an Animate Content Placeholder for Loading State in React
We will create animated Content Placeholder as React component just like Facebook has when you load ...
- 理解iOS 8中的Self Sizing Cells和Dynamic Type
http://www.cocoachina.com/ios/20140922/9717.html 在iOS 8中,苹果引入了UITableView的一项新功能--Self Sizing Cells,对 ...
- 《React Native 精解与实战》书籍连载「React Native 源码学习方法及其他资源」
此系列文章将整合我的 React 视频教程与 React Native 书籍中的精华部分,给大家介绍 React Native 源码学习方法及其他资源. 最后的章节给大家介绍 React Native ...
- 《React Native 精解与实战》书籍连载「React Native 底层原理」
此文是我的出版书籍<React Native 精解与实战>连载分享,此书由机械工业出版社出版,书中详解了 React Native 框架底层原理.React Native 组件布局.组件与 ...
- 《React Native 精解与实战》书籍连载「React 与 React Native 简介」
此文是我的出版书籍<React Native 精解与实战>连载分享,此书由机械工业出版社出版,书中详解了 React Native 框架底层原理.React Native 组件布局.组件与 ...
- [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 ...
- [React] Create and import React components with Markdown using MDXC
In this lesson I demonstrate how to use the library MDXC to create and import React components with ...
- [React] Create component variations in React with styled-components and "extend"
In this lesson, we extend the styles of a base button component to create multiple variations of but ...
- [React] Create & 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 ...
随机推荐
- Socket实例之客户端向服务端数据库上传文件UI版
http://blog.csdn.net/su20145104009/article/details/52843735 首先实现分析: 1用户注册 客户单选择‘用户注册’,提示要输入用户名,密码,确认 ...
- 洛谷 P2437 蜜蜂路线
P2437 蜜蜂路线 题目描述 一只蜜蜂在下图所示的数字蜂房上爬动,已知它只能从标号小的蜂房爬到标号大的相邻蜂房,现在问你:蜜蜂从蜂房M开始爬到蜂房N,M<N,有多少种爬行路线? 输入输出格式 ...
- ios UITextView 提示文本
定义两个UITextView,一个用于输入文本,一个用于显示提示信息,当输入文本为空时显示提示信息,否则不显示提示信息. //6.3.1文字内容提示 _contentTextViewTip = [[U ...
- postgresql 查看单个表大小
3中方法,不论什么一个都行 方法一 ,查一个表 select pg_size_pretty(pg_relation_size('table_name')); 方法二 ,查出全部表并按大小排序 SELE ...
- 内网使用 IPV6 之Teredo篇
这篇转载自 http://bbs.pcbeta.com/viewthread-1580771-1-1.html 上IPv6站点之Teredo篇http://bbs.pcbeta.com/viewthr ...
- fragment-实例创建跟使用
今天接触到了fragment,在网上看到了它的使用方法.现在把它的创建跟使用记录下,方便以后查询. 1.创建一个自己的fragment,继承自fragment package com.android. ...
- collapse折叠
基本: <button class="btn btn-primary" data-toggle="collapse" data-target=" ...
- 企业网管软件之SOLARWINDS实战-基于浏览器的网络流量监控
本文出自 "李晨光原创技术博客" 博客,谢绝转载!
- vue 键盘回车事件导致页面刷新的问题,路由多了一个问号
问题: <el-form @submit.native.prevent> <el-form-item > <el-input @keyup.enter.native=&q ...
- 原生js大总结十一
101.请简述prototype.__proto__ constructor三者的关系 1.prototype: 每一个函数都有一个prototype这个属性,而这个属性指向一个对象,这个 ...