React-virtualized,List在滚动时是Flickkering/lagging

Ale*_*sic 12 reactjs react-virtualized

当我滚动浏览列表时,我遇到了一些问题.还要注意底部的巨大空间.观看视频:https://vimeo.com/215349521

据我所知,我没有犯任何重大错误.但我确实相信问题是由于CellMeasurer.

Chrome版本:58.0.3029.81

class PromotionList extends Component {

constructor(props) {
    super(props);

    this.cache = new CellMeasurerCache({
        defaultHeight: 100,
        fixedWidth: true,
    });

    this.rowRenderer = this.rowRenderer.bind(this);
}

componentWillMount() {
    this.props.fetchPromotionsIfNeeded();
}

rowRenderer({ index, parent }) {
    const { promotions } = this.props;
    const data = promotions.list[index];

    return (
      <CellMeasurer
        cache={this.cache}
        columnIndex={0}
        key={uuid.v1()}
        parent={parent}
        rowIndex={index}
      >
        <BlobItem
          key={uuid.v1()}
          type={BlobTypes.promotion}
          data={data}
          onClick={this.props.onItemClick}
          index={index}
        />
      </CellMeasurer>
    );
}


render() {
    const { promotions, previewSize } = this.props;

    return (
      <List
        height={300}
        width={previewSize.width}
        rowCount={promotions.list.length}
        deferredMeasurementCache={this.cache}
        rowHeight={this.cache.rowHeight}
        rowRenderer={this.rowRenderer}
        className="blobList"
      />
    );
}
}
Run Code Online (Sandbox Code Playgroud)

Ale*_*sic 33

阅读完文档后找到解决方案.只需要在"rowRender"方法中添加样式:

rowRenderer({ index, parent, style }) {
  const { promotions } = this.props;
  const data = promotions.list[index];

  return (
    <CellMeasurer
      cache={this.cache}
      columnIndex={0}
      key={uuid.v1()}
      parent={parent}
      rowIndex={index}
    >
      <BlobItem
        key={uuid.v1()}
        type={BlobTypes.promotion}
        data={data}
        onClick={this.props.onItemClick}
        index={index}
        style={style}
      />
    </CellMeasurer>
  );
}
Run Code Online (Sandbox Code Playgroud)

  • 感谢您花时间回答自己的问题! (2认同)
  • 这个答案也对我有用。我只是在它周围扔了一个封闭的 &lt;div&gt; : &lt;div style={style&gt; &lt;BlobItem .... /&gt; &lt;/div&gt; @azium 我相信这必须以这种方式工作,因为我想虚拟化库是做时髦的绝对定位的事情来推动屏幕周围的单元格。没有造型,东西就会变得杂乱无章。 (2认同)