gpt4 book ai didi

reactjs - React-virtualized,列表在滚动时闪烁/滞后

转载 作者:行者123 更新时间:2023-12-03 13:15:17 39 4
gpt4 key购买 nike

当我滚动列表时遇到一些问题。还要注意底部的巨大空间。看视频:https://vimeo.com/215349521

据我所知,我没有犯任何重大错误。但我确实相信问题是由 CellMeasurer 造成的。

Chrome 版本:58.0.3029.81

class PromotionList extends Component {

constructor(props) {
super(props);

this.cache = new CellMeasurerCache({
defaultHeight: 100,
fixedWidth: true,
});

this.rowRenderer = this.rowRenderer.bind(this);
}

componentWillMount() {
this.props.fetchPromotionsIfNeeded();
}

rowRenderer({ index, parent }) {
const { promotions } = this.props;
const data = promotions.list[index];

return (
<CellMeasurer
cache={this.cache}
columnIndex={0}
key={uuid.v1()}
parent={parent}
rowIndex={index}
>
<BlobItem
key={uuid.v1()}
type={BlobTypes.promotion}
data={data}
onClick={this.props.onItemClick}
index={index}
/>
</CellMeasurer>
);
}


render() {
const { promotions, previewSize } = this.props;

return (
<List
height={300}
width={previewSize.width}
rowCount={promotions.list.length}
deferredMeasurementCache={this.cache}
rowHeight={this.cache.rowHeight}
rowRenderer={this.rowRenderer}
className="blobList"
/>
);
}
}

最佳答案

阅读文档后找到了解决方案。只需要在“rowRender”方法中添加样式即可:

rowRenderer({ index, parent, style }) {
const { promotions } = this.props;
const data = promotions.list[index];

return (
<CellMeasurer
cache={this.cache}
columnIndex={0}
key={uuid.v1()}
parent={parent}
rowIndex={index}
>
<BlobItem
key={uuid.v1()}
type={BlobTypes.promotion}
data={data}
onClick={this.props.onItemClick}
index={index}
style={style}
/>
</CellMeasurer>
);
}

关于reactjs - React-virtualized,列表在滚动时闪烁/滞后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43700938/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com