A tiny but mighty 3kb list virtualization library, with zero dependencies 💪 Supports variable heights/widths, sticky items, scrolling to index, and more!
I need to keep track of which items are visible outside of the VirtualList component. However, if I call setState in onItemsRendered, then React will correctly complain:
Warning: Cannot update during an existing state transition (such as within `render` or another component's constructor). Render methods should be a pure function of props and state; constructor side-effects are an anti-pattern, but can be moved to `componentWillMount`.
Is there are correct pattern for this? Ideally VirtualList would have a renderProp style prop that could look like ({ RenderedListNode, startIndex, endIndex}) => Node.
This is the code, it works in this simple example but causes the React warning and issues in more complicated code:
I need to keep track of which items are visible outside of the
VirtualList
component. However, if I callsetState
inonItemsRendered
, then React will correctly complain:Is there are correct pattern for this? Ideally VirtualList would have a renderProp style prop that could look like
({ RenderedListNode, startIndex, endIndex}) => Node
.This is the code, it works in this simple example but causes the React warning and issues in more complicated code: