【发布时间】:2020-01-20 11:25:59
【问题描述】:
我正在开发一个库,当我超过 200 个组件时出现性能问题。 目前在我的画廊中,我可以过滤图像并根据某些属性对它们进行排序。 我尝试使用“延迟加载”来提高性能,但它给我带来了以前没有的其他问题。此外,如果我仍然显示所有元素,它并不能解决问题。 我想尝试一个有点像“react-virtualized”的东西,它会永久更新 DOM,但我真的不知道该怎么做,而且我的印象是“react-virtualized”不适合与整个组件一起操作。
我的图库组件如下所示:
const Gallery = memo(props => {
const { imgs } = props;
const { onClickHere } = props;
return (
<div className="cards-container">
{imgs.map((img, index) => (
<GalleryImage
img={img}
index={index}
onClickHere={onClickHere}
/>
))}
</div>
);
});
我的图像组件看起来像这样:
const Image = props => {
const { img } = props;
const { index } = props;
const { onClickHere } = props;
const { alt } = props;
return (
<div className="cards-child">
<div className="gallery-card">
<img className="gallery-thumbnail" src={img.uri} alt={alt} />
<div className="card-info">
<span className="card-info_text">
<span className="badge badge-secondary">
{img.attr.join(", )}
</span>
</span>
</div>
<span className="card-icon-open fa fa-expand" onClick={e => {onClickHere(e, img, index);}} />
</div>
</div>
);
};
这些组件显示一个大小相同的可点击图像列表。 你知道我是否真的可以使用 react-virtualized 并且做得很糟糕(如果是这样的话,你能帮我看的更清楚)还是你知道提高这些性能的方法?
【问题讨论】:
标签: reactjs performance rendering react-virtualized