【问题标题】:Update list when redux store changesredux store 更改时更新列表
【发布时间】:2019-02-16 04:28:01
【问题描述】:

当我的 redux 存储发生更改时,我正在尝试更新列表,但由于某些奇怪的原因它不是。我必须手动刷新页面才能看到我的更改。这是我的 List 组件和 rowRenderer 的 sn-p。

    <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}
      />
    );
  };

【问题讨论】:

  • List 的任何道具是否发生了变化?我看到你有rowCount={visibleRequest.length}rowCount={rowCount}rowCount 是否保持不变?尝试将一个道具传递给List,当您想要触发重新渲染时该道具会发生变化,如果您不想更改rowCount,它可以是除此之外的任何道具

标签: javascript reactjs redux react-redux react-virtualized


【解决方案1】:

是的,我遇到了同样的问题。这是因为当你这样做时,对你的对象的引用不会改变

const row = this.getDatum(index);
    let content;
    if (loadedRowsMap[index] === STATUS_LOADED) {
      content = row;
    }

看看immutability

【讨论】:

  • @Shizam Gupta 我不明白你。你能试着解释得更好。谢谢。
  • 对您的对象的引用实际上并没有改变。当你这样做时。更新对象时需要更改对对象的引用。这样页面将使用更新的对象值重新呈现
猜你喜欢
  • 2020-06-24
  • 2020-06-07
  • 2018-09-27
  • 1970-01-01
  • 1970-01-01
  • 2020-03-10
  • 2020-08-10
  • 2019-04-09
  • 1970-01-01
相关资源
最近更新 更多