You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
***Render millions of items**, without breaking a sweat
18
-
***Scroll to index** or **set the initial scroll offset**
19
-
***Supports fixed** or **variable** heights/widths
20
-
***Vertical** or **Horizontal** lists
17
+
-**Tiny & dependency free** – Only 3kb gzipped
18
+
-**Render millions of items**, without breaking a sweat
19
+
-**Scroll to index** or **set the initial scroll offset**
20
+
-**Supports fixed** or **variable** heights/widths
21
+
-**Vertical** or **Horizontal** lists
21
22
22
23
Check out the [demo](https://clauderic.github.io/react-tiny-virtual-list/) for some examples, or take it for a test drive right away in [Code Sandbox](https://codesandbox.io/s/kymm7z9qr).
23
24
24
-
Getting Started
25
-
---------------
25
+
## Getting Started
26
26
27
27
Using [npm](https://www.npmjs.com/):
28
+
28
29
```
29
30
npm install react-tiny-virtual-list --save
30
31
```
31
32
32
33
ES6, CommonJS, and UMD builds are available with each distribution. For example:
| width | Number or String*| ✓ | Width of List. This property will determine the number of rendered items when scrollDirection is `'horizontal'`. |
76
-
| height | Number or String*| ✓ | Height of List. This property will determine the number of rendered items when scrollDirection is `'vertical'`. |
77
-
| itemCount | Number | ✓ | The number of items you want to render |
78
-
| renderItem | Function | ✓ | Responsible for rendering an item given it's index: `({index: number, style: Object}): React.PropTypes.node`. The returned element must handle key and style. |
79
-
| itemSize || ✓ | Either a fixed height/width (depending on the scrollDirection), an array containing the heights of all the items in your list, or a function that returns the height of an item given its index: `(index: number): number`|
80
-
| scrollDirection | String || Whether the list should scroll vertically or horizontally. One of `'vertical'` (default) or `'horizontal'`. |
81
-
| scrollOffset | Number || Can be used to control the scroll offset; Also useful for setting an initial scroll offset |
82
-
| scrollToIndex | Number || Item index to scroll to (by forcefully scrolling if necessary) |
83
-
| scrollToAlignment | String || Used in combination with `scrollToIndex`, this prop controls the alignment of the scrolled to item. One of: `'start'`, `'center'`, `'end'` or `'auto'`. Use `'start'` to always align items to the top of the container and `'end'` to align them bottom. Use `'center`' to align them in the middle of the container. `'auto'` scrolls the least amount possible to ensure that the specified `scrollToIndex` item is fully visible. |
84
-
| overscanCount | Number || Number of extra buffer items to render above/below the visible items. Tweaking this can help reduce scroll flickering on certain browsers/devices. |
85
-
| estimatedItemSize | Number || Used to estimate the total size of the list before all of its items have actually been measured. The estimated total height is progressively adjusted as items are rendered. |
86
-
| onItemsRendered | Function || Callback invoked with information about the slice of rows/columns that were just rendered. It has the following signature: `({startIndex: number, stopIndex: number})`. |
87
-
| onScroll | Function || Callback invoked whenever the scroll offset changes within the inner scrollable region. It has the following signature: `(scrollTop: number, event: React.UIEvent<HTMLDivElement>)`. |
88
-
89
-
*\* Width may only be a string when `scrollDirection` is `'vertical'`. Similarly, Height may only be a string if `scrollDirection` is `'horizontal'`*
| width | Number \| String\*| ✓ | Width of List. This property will determine the number of rendered items when scrollDirection is `'horizontal'`. |
79
+
| height | Number \| String\*| ✓ | Height of List. This property will determine the number of rendered items when scrollDirection is `'vertical'`. |
80
+
| itemCount | Number | ✓ | The number of items you want to render |
81
+
| renderItem | Function | ✓ | Responsible for rendering an item given it's index: `({index: number, style: Object}): React.PropTypes.node`. The returned element must handle key and style. |
82
+
| itemSize || ✓ | Either a fixed height/width (depending on the scrollDirection), an array containing the heights of all the items in your list, or a function that returns the height of an item given its index: `(index: number): number`|
83
+
| scrollDirection | String || Whether the list should scroll vertically or horizontally. One of `'vertical'` (default) or `'horizontal'`. |
84
+
| scrollOffset | Number || Can be used to control the scroll offset; Also useful for setting an initial scroll offset |
85
+
| scrollToIndex | Number || Item index to scroll to (by forcefully scrolling if necessary) x |
86
+
| scrollToAlignment | String || Used in combination with `scrollToIndex`, this prop controls the alignment of the scrolled to item. One of: `'start'`, `'center'`, `'end'` or `'auto'`. Use `'start'` to always align items to the top of the container and `'end'` to align them bottom. Use `'center`' to align them in the middle of the container. `'auto'` scrolls the least amount possible to ensure that the specified `scrollToIndex` item is fully visible. |
87
+
| stickyIndices | Number[]|| An array of indexes (eg. `[0, 10, 25, 30]`) to make certain items in the list sticky (`position: sticky`) |
88
+
| overscanCount | Number || Number of extra buffer items to render above/below the visible items. Tweaking this can help reduce scroll flickering on certain browsers/devices. |
89
+
| estimatedItemSize | Number || Used to estimate the total size of the list before all of its items have actually been measured. The estimated total height is progressively adjusted as items are rendered. |
90
+
| onItemsRendered | Function || Callback invoked with information about the slice of rows/columns that were just rendered. It has the following signature: `({startIndex: number, stopIndex: number})`. |
91
+
| onScroll | Function || Callback invoked whenever the scroll offset changes within the inner scrollable region. It has the following signature: `(scrollTop: number, event: React.UIEvent<HTMLDivElement>)`. |
92
+
93
+
_\* Width may only be a string when `scrollDirection` is `'vertical'`. Similarly, Height may only be a string if `scrollDirection` is `'horizontal'`_
90
94
91
95
### Public Methods
92
96
93
97
#### recomputeSizes (index: number)
98
+
94
99
This method force recomputes the item sizes after the specified index (these are normally cached).
95
100
96
101
`VirtualList` has no way of knowing when its underlying data has changed, since it only receives a itemSize property. If the itemSize is a `number`, this isn't an issue, as it can compare before and after values and automatically call `recomputeSizes` internally.
97
-
However, if you're passing a function to `itemSize`, that type of comparison is error prone. In that event, you'll need to call `recomputeSizes` manually to inform the `VirtualList` that the size of its items has changed.
102
+
However, if you're passing a function to `itemSize`, that type of comparison is error prone. In that event, you'll need to call `recomputeSizes` manually to inform the `VirtualList` that the size of its items has changed.
103
+
104
+
### Common Issues with PureComponent
98
105
99
-
### Common Issues with PureComponent
100
106
`react-tiny-virtual-list` uses [PureComponent](https://reactjs.org/docs/react-api.html#reactpurecomponent), so it only updates when it's props change. Therefore, if only the order of your data changes (eg `['a','b','c']` => `['d','e','f']`), `react-tiny-virtual-list` has no way to know your data has changed and that it needs to re-render.
101
107
102
108
You can force it to re-render by calling [forceUpdate](https://reactjs.org/docs/react-component.html#forceupdate) on it or by passing it an extra prop that will change every time your data changes.
103
109
104
110
## Reporting Issues
111
+
105
112
Found an issue? Please [report it](https://github.com/clauderic/react-tiny-virtual-list/issues) along with any relevant details to reproduce it. If you can, please provide a live demo replicating the issue you're describing. You can [fork this Code Sandbox](https://codesandbox.io/s/kymm7z9qr) as a starting point.
106
113
107
114
## Contributions
115
+
108
116
Feature requests / pull requests are welcome, though please take a moment to make sure your contributions fits within the scope of the project. [Learn how to contribute](https://github.com/clauderic/react-tiny-virtual-list/blob/master/CONTRIBUTING.md)
109
117
110
118
## Acknowledgments
119
+
111
120
This library draws inspiration from [react-virtualized](https://github.com/bvaughn/react-virtualized), and is meant as a bare-minimum replacement for the [List](https://github.com/bvaughn/react-virtualized/blob/master/docs/List.md) component. If you're looking for a tiny, lightweight and dependency-free list virtualization library that supports variable heights, you're in the right place! If you're looking for something that supports more use-cases, I highly encourage you to check out [react-virtualized](https://github.com/bvaughn/react-virtualized) instead, it's a fantastic library ❤️
112
121
113
122
## License
123
+
114
124
react-tiny-virtual-list is available under the MIT License.
0 commit comments