javascript - redux store 更改时更新列表
问题描述
当我的 redux 存储发生更改时,我正在尝试更新列表,但出于某种奇怪的原因,它不是。我必须手动刷新页面才能看到我的更改。这是我的 List 组件和 rowRenderer 的片段。
<InfiniteLoader
isRowLoaded={this._isRowLoaded}
loadMoreRows={this._loadMoreRows}
rowCount={visibleRequest.length}
>
{({ onRowsRendered, registerChild }) => (
<AutoSizer>
{({ height, width }) => (
<List
ref={registerChild}
className="List"
height={height}
rowHeight={listRowHeight}
onRowsRendered={onRowsRendered}
rowCount={rowCount}
rowRenderer={this._rowRenderer}
width={width}
/>
)}
</AutoSizer>
)}
</InfiniteLoader>
_rowRenderer = ({ index, key, style }) => {
const { loadedRowsMap, selected } = this.state;
const row = this.getDatum(index);
let content;
if (loadedRowsMap[index] === STATUS_LOADED) {
content = row;
} else {
content = (
<div className="placeholder" style={{ width: _.random(100, 200) }} />
);
}
return (
<PendingChat
key={key}
content={content}
style={style}
row={row}
{...this.props}
/>
);
};
解决方案
是的,我遇到了同样的问题。这是因为当您这样做时,对您的对象的引用不会改变
const row = this.getDatum(index);
let content;
if (loadedRowsMap[index] === STATUS_LOADED) {
content = row;
}
看看不变性。
推荐阅读
- android - 如何在 RecycledView 项目之间添加空格
- javascript - HTML/Javscript - 接受 10 以外的其他基数的数字输入
- python - 如何在 tkinter.messagebox.showinfo() 小部件中取消用于显示消息的字体?
- python - 将 psycopg2 光标传递给 tweepy on_status() 方法
- html - 为什么这个 Bootstrap 4 Navbar 不能创建等宽的菜单项?
- docker - gRPC 流式处理过程返回“方法未实现”。在 Azure 容器实例中运行时
- r - R Shiny - 自定义选项不适用于tippy::with_tippy()
- xodus - 如何使用 Xodus DNQ 检查组合唯一性
- ios - 从 SwiftUI 上的部分列表中删除项目
- single-sign-on - SAML 属性经常实现 eduPerson 规范?有没有更通用的规范?