首页 > 解决方案 > 对于反应虚拟化的砌体,处理删除项目的推荐方法是什么?

问题描述

https://codesandbox.io/s/l79vn4rowq

删除项目时,我没有重新初始化 cellMeasurerCache,因为我已经有了每个项目的尺寸。invalidateCellSizeAfterRender通过这样做,不会设置填充位置缓存的上限和下限,因为如果缓存中已经存在维度,则 CellMeasurer 不会调用。

      //hack to set a range for populating position cache
      masonryInstance.invalidateCellSizeAfterRender({ rowIndex: 0 });
      masonryInstance.invalidateCellSizeAfterRender({
        rowIndex: batchSize - 1
      });

      //populate position cache
      masonryInstance.recomputeCellPositions();

我不得不使用 hack 方法invalidateCellSizeAfterRender来设置填充位置缓存的上限和下限。有一个更好的方法吗?

标签: reactjsmasonryreact-virtualized

解决方案


推荐阅读