0

I have react-virtualized list that gets populated with data that comes from an API call which stores fetched data in the redux store. An action to begin fetching data from the API is dispatched when the component mounts, the data arrives and gets saved in the store but the react-virtualized list doesn't get updated with this data until the page is manually refreshed a couple of times before the data shows up in the List. Also there is an API poll running in the background to fetch updated data which will then get displayed in the list.

How do I configure the List to listen for when data arrives and displays the data accordingly (To listen for changes to the redux store). Here is my implementation of the react-virtualized InfiniteLoader & List:

< InfiniteLoader
isRowLoaded = {
  this._isRowLoaded
}
loadMoreRows = {
  this._loadMoreRows
}
rowCount = {
    visibleRequest.length
  } > {
    ({
      onRowsRendered,
      registerChild
    }) => ( <
      AutoSizer > {
        ({
          height,
          width
        }) => (
          <List ref = {ref => (this.registerChild = ref)}
          className = "List"
          height = {height}
          rowHeight = {listRowHeight}
          onRowsRendered = {onRowsRendered}
          rowCount = {rowCount}
          rowRenderer = {this._rowRenderer}
          width = {width}
          />
        )
      }
      </AutoSizer>
    )
  }
  </InfiniteLoader>

// rowRenderer function
_rowRenderer = ({
  index,
  key,
  style
}) => {
  const {
    loadedRowsMap,
    selected
  } = this.state;
  const row = this.getDatum(index);
  let content;
  if (loadedRowsMap[index] === STATUS_LOADED) {
    content = row;
  } else {
    content = ( <div className = "placeholder"
      style = {
        {
          width: _.random(100, 200)
        }
      }
      />
    );
  }
  return ( <NewRequest key = {key}
    content = {content}
    style = {style}
    row = {row}
    {...this.props}
    />
  );
};
Dave Kalu
  • 1,520
  • 3
  • 19
  • 38
  • It would be really helpful if you [created a codesandbox link](https://codesandbox.io/s/new) to an example of your problem – Ninjakannon Sep 17 '18 at 09:45
  • Okay i will do that. But you could still take a stab at it. I think I was detailed enough with my explanation. :) Thanks. – Dave Kalu Sep 17 '18 at 09:47
  • I don't think you have been detailed enough actually. The problem is likely the wiring between redux and the parent component, neither of which is visible here. It also likely has nothing to do with react-virtualized. – Nathan Power Sep 17 '18 at 11:53

0 Answers0