1. # react-window
    
  2. 
    
  3. > React components for efficiently rendering large lists and tabular data
    
  4. 
    
  5. [![NPM registry](https://img.shields.io/npm/v/react-window.svg?style=for-the-badge)](https://yarnpkg.com/en/package/react-window) [![Travis](https://img.shields.io/badge/ci-travis-green.svg?style=for-the-badge)](https://travis-ci.org/bvaughn/react-window) [![NPM license](https://img.shields.io/badge/license-mit-red.svg?style=for-the-badge)](LICENSE.md)
    
  6. 
    
  7. ## Install
    
  8. 
    
  9. ```bash
    
  10. # Yarn
    
  11. yarn add react-window
    
  12. 
    
  13. # NPM
    
  14. npm install --save react-window
    
  15. ```
    
  16. 
    
  17. ## Usage
    
  18. 
    
  19. Learn more at [react-window.now.sh](https://react-window.now.sh/):
    
  20. 
    
  21. ## Related libraries
    
  22. 
    
  23. * [`react-virtualized-auto-sizer`](https://npmjs.com/package/react-virtualized-auto-sizer): HOC that grows to fit all of the available space and passes the width and height values to its child.
    
  24. * [`react-window-infinite-loader`](https://npmjs.com/package/react-window-infinite-loader): Helps break large data sets down into chunks that can be just-in-time loaded as they are scrolled into view. It can also be used to create infinite loading lists (e.g. Facebook or Twitter).
    
  25. 
    
  26. ## Frequently asked questions
    
  27. 
    
  28. ### How is `react-window` different from `react-virtualized`?
    
  29. I wrote `react-virtualized` several years ago. At the time, I was new to both React and the concept of windowing. Because of this, I made a few API decisions that I later came to regret. One of these was adding too many non-essential features and components. Once you add something to an open source project, removing it is pretty painful for users.
    
  30. 
    
  31. `react-window` is a complete rewrite of `react-virtualized`. I didn't try to solve as many problems or support as many use cases. Instead I focused on making the package **smaller**<sup>1</sup> and **faster**. I also put a lot of thought into making the API (and documentation) as beginner-friendly as possible (with the caveat that windowing is still kind of an advanced use case).
    
  32. 
    
  33. If `react-window` provides the functionality your project needs, I would strongly recommend using it instead of `react-virtualized`. However if you need features that only `react-virtualized` provides, you have two options:
    
  34. 
    
  35. 1. Use `react-virtualized`. (It's still widely used by a lot of successful projects!)
    
  36. 2. Create a component that decorates one of the `react-window` primitives and adds the functionality you need. You may even want to release this component to NPM (as its own, standalone package)! 🙂
    
  37. 
    
  38. <sup>1 - Adding a `react-virtualized` list to a CRA project increases the (gzipped) build size by ~33.5 KB. Adding a `react-window` list to a CRA project increases the (gzipped) build size by &lt;2 KB.</sup>
    
  39. 
    
  40. ### Can a list or a grid fill 100% the width or height of a page?
    
  41. 
    
  42. Yes. I recommend using the [`react-virtualized-auto-sizer` package](https://npmjs.com/package/react-virtualized-auto-sizer):
    
  43. 
    
  44. <img width="336" alt="screen shot 2019-03-07 at 7 29 08 pm" src="https://user-images.githubusercontent.com/29597/54005716-50f41880-410f-11e9-864f-a65bbdf49e07.png">
    
  45. 
    
  46. Here's a [Code Sandbox demo](https://codesandbox.io/s/3vnx878jk5).
    
  47. 
    
  48. ### Why is my list blank when I scroll?
    
  49. 
    
  50. If your list looks something like this...
    
  51. 
    
  52. <img src="https://user-images.githubusercontent.com/29597/54005352-eb535c80-410d-11e9-80b2-d3d02db1f599.gif" width="302" height="152">
    
  53. 
    
  54. ...then you probably forgot to use the `style` parameter! Libraries like react-window work by absolutely positioning the list items (via an inline style), so don't forget to attach it to the DOM element you render!
    
  55. 
    
  56. <img width="257" alt="screen shot 2019-03-07 at 7 21 48 pm" src="https://user-images.githubusercontent.com/29597/54005433-45ecb880-410e-11e9-8721-420ff1a153da.png">
    
  57. 
    
  58. ### Can I lazy load data for my list?
    
  59. 
    
  60. Yes. I recommend using the [`react-window-infinite-loader` package](https://npmjs.com/package/react-window-infinite-loader):
    
  61. 
    
  62. <img width="368" alt="screen shot 2019-03-07 at 7 32 32 pm" src="https://user-images.githubusercontent.com/29597/54006733-653a1480-4113-11e9-907b-08ca5e27b3f9.png">
    
  63. 
    
  64. Here's a [Code Sandbox demo](https://codesandbox.io/s/5wqo7z2np4).
    
  65. 
    
  66. ### Can I attach custom properties or event handlers?
    
  67. 
    
  68. Yes, using the `outerElementType` prop.
    
  69. 
    
  70. <img width="412" alt="Screen Shot 2019-03-12 at 8 58 09 AM" src="https://user-images.githubusercontent.com/29597/54215333-f9ee9a80-44a4-11e9-9142-34c67026d950.png">
    
  71. 
    
  72. Here's a [Code Sandbox demo](https://codesandbox.io/s/4zqx79nww0).
    
  73. 
    
  74. ### Can I add gutter or padding between items?
    
  75. 
    
  76. Yes, although it requires a bit of inline styling.
    
  77. 
    
  78. <img width="416" alt="Screen Shot 2019-03-26 at 6 33 56 PM" src="https://user-images.githubusercontent.com/29597/55043972-c14ad700-4ff5-11e9-9caa-2e9f4d85f96c.png">
    
  79. 
    
  80. Here's a [Code Sandbox demo](https://codesandbox.io/s/2w8wmlm89p).
    
  81. 
    
  82. ### Does this library support "sticky" items?
    
  83. 
    
  84. Yes, although it requires a small amount of user code. Here's a [Code Sandbox demo](https://codesandbox.io/s/0mk3qwpl4l).
    
  85. 
    
  86. ## License
    
  87. 
    
  88. MIT © [bvaughn](https://github.com/bvaughn)