在调整浏览器窗口大小时清除与react-window-infinite-loader一起使用的react-window列表的缓存
我按照以下方式使用 VariableSizedList
以及 InfiniteLoader
和 AutoSizer
{({ width, height }) => (
<InfiniteLoader
isItemLoaded={isItemLoaded}
itemCount={itemCount}
loadMoreItems={loadMore}
>
{({ onItemsRendered, ref }) => (
<VariableSizeList
itemCount={itemCount}
onItemsRendered={onItemsRendered}
// IMP: ref callback gets created on every render. Plus is it safe to do inner list modifications?
ref={(variableSizeList) => {
if (typeof ref === "function") {
ref(variableSizeList);
}
variableSizeListRef.current = variableSizeList;
}}
estimatedItemSize={getItemSizeForColumnLayoutIfRequired(
estimatedItemSize
)}
itemSize={getListItemSize}
itemData={{ listData, columnView, ...additionalDataProps }}
width={width}
height={height}
itemKey={itemKey}
overscanCount={overScanCount || 5}
outerRef={listContainerRef}
>
{children}
</VariableSizeList>
)}
</InfiniteLoader>
我的场景:对于宽度 >我正在连续渲染两个项目,但是当条件失败时,我想将每个项目渲染在另一个项目的下面。为此,我使用 flex-wrap 将项目一个接一个地放在另一个下面,同时我更改每行的大小以适应包装。
我的问题:在检测和设置状态以指示列视图时,如果没有上述引用回调代码,我无法重置列表。由于 ref 回调必须创建为内联函数(以设置无限加载器列表的 ref),因此在每次渲染时都会调用该回调,这并不理想。另外,我不确定直接选择可变大小列表的引用并对其进行更改是否会影响无限列表组件的工作。
我的问题:这样传递裁判会导致任何问题吗?还有其他方法吗?我可以重新计算我的列表并更改其结构以匹配列视图,但这是一项有点乏味的任务。
我尝试过: 获取无限列表的 ref 并调用其唯一的公共方法 resetloadMoreItemsCache(true)
;但是,这不会重新计算我现有行的高度。
I am using VariableSizedList
along with the InfiniteLoader
and AutoSizer
in the following manner
{({ width, height }) => (
<InfiniteLoader
isItemLoaded={isItemLoaded}
itemCount={itemCount}
loadMoreItems={loadMore}
>
{({ onItemsRendered, ref }) => (
<VariableSizeList
itemCount={itemCount}
onItemsRendered={onItemsRendered}
// IMP: ref callback gets created on every render. Plus is it safe to do inner list modifications?
ref={(variableSizeList) => {
if (typeof ref === "function") {
ref(variableSizeList);
}
variableSizeListRef.current = variableSizeList;
}}
estimatedItemSize={getItemSizeForColumnLayoutIfRequired(
estimatedItemSize
)}
itemSize={getListItemSize}
itemData={{ listData, columnView, ...additionalDataProps }}
width={width}
height={height}
itemKey={itemKey}
overscanCount={overScanCount || 5}
outerRef={listContainerRef}
>
{children}
</VariableSizeList>
)}
</InfiniteLoader>
My Scenario: For width > tablet I'm rendering two items in a row, but when the condition fails, I want to render each item one below the other. For this I'm using flex-wrap to get the items one below the other, and at the same time I'm changing the size of each row to accommodate the wrapping.
My Problem: On detecting and setting a state to indicate column view, I'm unable to reset the list without the above ref callback code. Since the ref callback has to be created as an inline function (to set the ref of infinite loader list), the callback is called on every render which is not ideal. Plus I'm not sure if picking the ref of the variable sized list directly and making change to it would impact the working of the infinite list component.
My question: Will by passing the ref like this cause any problems? Is there another way to do it? I could recompute my list and change its structure to match the column view, but that's a bit of a tedious task.
What I have tried:
Took the ref of the infinite list and called its only public method resetloadMoreItemsCache(true)
; however this does not re-compute the heights of my existing rows.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为如果您使用
variableSizeListRef.current.resetAfterIndex(0)
它应该重新计算高度。I think if you use
variableSizeListRef.current.resetAfterIndex(0)
it should recompute the height.