Closed idrm closed 6 years ago
@idrm I'm having the same issue. As a workaround I added a key property to the VirtualList and assigned it to Date.now()
so it will rerender.
<VirtualList key={Date.now()} ... />
Won't that needlessly unmount/re-mount the list upon each render run of its enclosing component?
If you want to force the component to re-render, pass it an extra prop such as forceUpdate={shouldComponentUpdate}
. You can refer to this section of the README https://github.com/clauderic/react-tiny-virtual-list#common-issues-with-purecomponent.
There's currently an issue around this, as it will cause a React warning, but there is a workaround, see #59.
The solution @weaintplastic mentioned should be avoided, as it will indeed needlessly unmount and re-mount the entire component on each subsequent render of the parent component, which would kill performance and cause it to lose it's current scroll position.
Is there a reason why
VirtualList
extendsPureComponent
instead ofComponent
?In my use case (a checkbox list) I find that I have to re-generate the
renderItem
prop in order to fool the virtual list into re-rendering itself.I think it would make more sense to use
Component
, and let the user decide when and how to "purify" its rendering based on some state change.Alternately, a
pure
prop that defaulted totrue
(in order to keep VirtualList backward compatible) could be added to return a component of the corresponding type.