What's the right way to reset / initialize InfiniteLoader
react-redux, react-virtualized, reactjs
Solution
For newer versions of `InfiniteLoader`
Since this question has been posted, `InfiniteLoader` has gained a parameter which auto-reloads the data. You can now use:
infiniteLoaderRef.resetLoadMoreRowsCache(true);
to automatically flush the cache and get new rows.
For older versions of `InfiniteLoader`
`InfiniteLoader` reacts to a range of rows being rendered. The `resetLoadMoreRowsCache` method just resets cached data. It doesn't automatically request a batch of rows be loaded.
Arguably it should. I don't know. It seemed easy enough for user code to auto-load the first batch of new data if the application state has changed in such a way as to require `resetLoadMoreRowsCache` to be called.
Anyway, tl;dr is that you should be able to do this:
infiniteLoaderRef.resetLoadMoreRowsCache(); // Reset the cache
loadMoreRows({ // Manually kick off the first batch
startIndex: 0,
stopIndex: 20 // Or whatever
});
Happy to review a PR to change the default behavior if you feel it could be improved.
Problem
I'm trying to use `InfiniteLoader` from the `react-virtualize` library to show up a scrollable list that has a `textSearch` input field on top (used to filter list entries). The code I use is very close to the InfiniteLoader Sample Code. The list is working fine, but I'm not sure how to reset/initialize the `InfiniteLoader` when the `searchText` is changed and (completely) new data should be shown. The flow is like this: - the list is opened for the first time and shows data from the `redux store` (works fine). - user changes `textSearch` and new data is fetched to the `store` - at this point, `InfiniteLoader` should be be initialized (I tried calling `resetLoadMoreRowsCache` on `InfiniteLoader`) - `InfiniteLoader` should call `loadMoreRows` like for the first time and rerender with the new data I've seen that the INFINITELOADER DEMO has the same behaviour: by clicking 'Flush Cached Data' nothing happens until I start scolling the list. So my question: what is the right way to reset/initialize?