为什么 Masonry 不在 componentWillReceiveProps 方法上刷新单元格 (cellCount) 的索引?

Why doesn't Masonry refresh indexes of cells (cellCount) on componentWillReceiveProps method?

每个下一个搜索查询都从上一个页面高度和索引计数开始。 如何更新 cellRenderer 中的索引计数和新搜索查询的页面高度? 下一段代码有助于避免错误,但不能解决问题:

cellRenderer = ({index, key, parent, style}) => {
    const image = this.props.images.items[index];

    if (!image) {
        console.log('!image (empty image with index: ', index, 'style', style);
        return;
    }

代码:pastebin.com/FB7kzDb4

tl;dr 您可以通过执行以下操作来修复您的演示:

// Clear any JIT measurements
cellMeasurerCache.clearAll();

// Reset the position cache
cellPositioner.reset({
  columnCount: this.columnCount,
  columnWidth: this.columnWidth,
  spacer: this.spacer,
});

// Let Masonry know it needs to relayout
this.masonry.clearCellPositions();

Here is an example of me doing the same on the RV demo page. You can see it running here 通过单击 "Reset List" 按钮。