Может только получить React-Virtualized InfiniteLoader для загрузки первой строки

Я застрял на этом немного. Я пытался имитировать [пример удаленного загрузчика][1], найденный в документации, но я могу получить только первые строки для загрузки. Как будто после этого список не обновляется. Я вышел из системы startIndex и stopIndex, в дополнение ко всем значениям в моем rowRenderer. Что может быть причиной загрузки только первых 16 элементов? (затем пробел внизу)

class LocationsGrid extends React.Component {
  state = {
    data: [],
    loading: false
  };

  loadedRowsMap = {};

  isRowLoaded = ({ index }) => {
    return !!this.loadedRowsMap[index];
  };

  loadMoreRows = ({ startIndex, stopIndex }) => {

    let { data } = this.state;
    const newState = [];

    for (let i = startIndex; i <= stopIndex; i += 1) {
      this.loadedRowsMap[i] = 1;

      let location = this.props.locations[i];
      newState.push(location);
    }

    this.setState({
      data: newState
    });
  };


  render() {
    const { locations, classes } = this.props;


    return (
      <div className={classes.root}>
        <div style={{ display: "inline" }}>
          <SubtitleSection />
        </div>

        <InfiniteLoader
          isRowLoaded={this.isRowLoaded}
          loadMoreRows={this.loadMoreRows}
          rowCount={locations.length}
        >
          {({ onRowsRendered, registerChild }) => (
            <AutoSizer>
              {({ height, width }) => {
                const itemsPerRow = Math.floor((width - 20) / CARD_WIDTH) || 1;
                const rowCount = Math.ceil(locations.length / itemsPerRow);

                return (
                  <div>
                    <List
                      width={width}
                      height={height}
                      ref={registerChild}
                      onRowsRendered={onRowsRendered}
                      rowCount={rowCount}
                      rowHeight={CARD_WIDTH + 20}
                      rowRenderer={({ index, key, style }) => {
                        const items = [];

                        const fromIndex = index * itemsPerRow;

                        const toIndex = Math.min(
                          fromIndex + itemsPerRow,
                          locations.length
                        );

                        for (let i = fromIndex; i < toIndex; i++) {
                          let location = this.state.data[i];

                          items.push(
                            <div className={classes.Item} key={i}>
                              <LocationCard location={location} />
                            </div>
                          );
                        }



                        return (
                          <div className={classes.Row} key={key} style={style}>
                            {items}
                          </div>
                        );
                      }}
                    />
                  </div>
                );
              }}
            </AutoSizer>
          )}
        </InfiniteLoader>
      </div>
    );
  }
}




  [1]: https://github.com/bvaughn/react-virtualized/blob/master/docs/InfiniteLoader.md#examples

0 ответов

Другие вопросы по тегам