Let\'s say I have a list of 1000 items. And I rendering it with React, like this:
class Parent extends React.Component {
render() {
// this.state.list is a
There are a few things you can do:
NODE_ENV=production npm run build
or similar. ReactJS performs a lot of safety checks when NODE_ENV
is not set to production, such as PropType checks. Switching these off should give you a >2x performance improvement for React rendering, and is vital for your production build (though leave it off during development - those safety checks help prevent bugs!). You may find this is good enough for the number of items you need to support.firstRendered
/lastRendered
props to your List state (that's first inclusive and last exclusive of course). In List.render
, render a filler blank div
(or tr
if applicable) of the correct height (firstRendered * itemHeight
), then your rendered range of items [firstRendered, lastRendered)
, then another filler div with the remaining height ((totalItems - lastRendered) * itemHeight
). Make sure you give your fillers and items fixed keys. You then just need to handle onScroll on the scrollable div, and work out what the correct range to render is (generally you want to render a decent overlap off the top and bottom, also you want to only trigger a setState to change the range when you get near to the edge of it). A crazier alternative is to render and implement your own scrollbar (which is what Facebook's own FixedDataTable does I think - https://facebook.github.io/fixed-data-table/). There are lots of examples of this general approach here https://react.rocks/tag/InfiniteScroll