简体   繁体   English

使用 react-window 滚动时出现故障的问题是什么?

[英]What is the problem of glitch when scrolling using react-window?

I want to do row virtualization when scrolling (so that data is shown when scrolling)我想在滚动时进行行虚拟化(以便滚动时显示数据)

But when scrolling, now the terrible glitches appear但是在滚动时,现在出现了可怕的故障

Tell me what is the problem?告诉我有什么问题?

project - male-wind.surge.sh项目 -男性wind.surge.sh

A component with a table (react-window is used there):带有表格的组件(那里使用了反应窗口):

import React, { Component } from "react";
import { connect } from "react-redux";
import actions from "../../actions";
import PropTypes from "prop-types";
import sort from "./sort";
import { FixedSizeList } from 'react-window';

function TitleColumn(data) {
  return (
    <Grid item xs={1}>
      <Box className="title_elem">
        <h3
          className="table_title-text"
          onClick={sort.bind(null, `${data.title.toLowerCase()}`, data.props)}
        >
          {data.title}
        </h3>
        {data.props.fourthData.data === `${data.title.toLowerCase()}` ? (
          <p>{data.props.fifthData.data}</p>
        ) : null}
      </Box>
    </Grid>
  );
}


class Table extends Component {
  render() {
    const data = this.props.info;
    const Row = ({ index, style}) => {
      return (
        <Grid container className="table_row">
          <Grid item xs={1}>
            <Box className="table_elem name_elem">{data[index].name}</Box>
          </Grid>
          <Grid item xs={1}>
            <Box className="table_elem job_elem">{data[index].job}</Box>
          </Grid>
          <Grid item xs={1}>
            <Box className="table_elem city_elem">{data[index].city}</Box>
          </Grid>
          <Grid item xs={1}>
            <Box className="table_elem country_elem">{data[index].country}</Box>
          </Grid>
          <Grid item xs={1}>
            <Box className="table_elem latitude_elem">{data[index].latitude}</Box>
          </Grid>
          <Grid item xs={1}>
            <Box className="table_elem longitude_elem">{data[index].longitude}</Box>
          </Grid>
          <Grid item xs={1}>
            <Box className="table_elem date_elem">
              {`${data[index].date.toLocaleString("en", {
            year: "numeric",
            month: "long",
            day: "numeric"
          })}`}
            </Box>
          </Grid>
        </Grid>
      )
    };
    return (
        <Grid
          container
          className="developer_block-time_feature time_feature_block"
        >
          <Grid container className="table_title">
            <TitleColumn props={this.props} title="Name" />
            <TitleColumn props={this.props} title="Job" />
            <TitleColumn props={this.props} title="City" />
            <TitleColumn props={this.props} title="Country" />
            <TitleColumn props={this.props} title="Latitude" />
            <TitleColumn props={this.props} title="Longitude" />
            <TitleColumn props={this.props} title="Date" />
          </Grid>
          <FixedSizeList                 <---------------use react-window
            height={500} 
            itemSize={60}
            itemCount={data.length}
            className="list-container"
          >
            {Row}
          </FixedSizeList>
        </Grid>
    );
  }
}

Table.propTypes = {
  fourthData: PropTypes.object.isRequired,
  fifthData: PropTypes.object.isRequired
};

const mapStateToProps = store => {
  return {
    firstData: store.firstData,
    secondData: store.secondData,
    thirdData: store.thirdData,
    fourthData: store.fourthData,
    fifthData: store.fifthData
  };
};

const mapDispatchToProps = dispatch => {
  return {
    setData: data => dispatch(actions.setData(data)),
    changeSearchData: searchData =>
      dispatch(actions.changeSearchData(searchData)),
    changeSort: sort => dispatch(actions.changeSort(sort)),
    setSortTitle: sortField => dispatch(actions.setSortTitle(sortField)),
    changeArrow: arrow => dispatch(actions.changeArrow(arrow))
  };
};

export default connect(mapStateToProps, mapDispatchToProps)(Table);

I try to use this solution, but it does not help - https://github.com/bvaughn/react-virtualized/issues/1327我尝试使用此解决方案,但它没有帮助 - https://github.com/bvaughn/react-virtualized/issues/1327

you have to apply the style passed by list for list element rendering which sets height, width and top attributes.您必须将列表传递的样式应用于设置高度、宽度和顶部属性的列表元素呈现。 you can do as below你可以做如下

const Row = ({ index, style}) => {
      return (
        <Grid container className="table_row" style={style}>
          <Grid item xs={1}>
            <Box className="table_elem name_elem">{data[index].name}</Box>
          </Grid>....…..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM