简体   繁体   English

ant.design 表未更新

[英]ant.design table is not updated

Trying to use this component https://ant.design/components/table/尝试使用此组件https://ant.design/components/table/

I've put together a simple example here https://codesandbox.io/s/loving-hopper-wly0x我在这里整理了一个简单的例子https://codesandbox.io/s/loving-hopper-wly0x

I expect to see a spinner instead of a link when I click on "Reload" action, but I only see console.log being printed.当我单击“重新加载”操作时,我希望看到一个微调器而不是一个链接,但我只看到正在打印console.log

Actually it came out to be even worse than I have locally with Mobx as a data-layer - there I have to move the cursor away from the row or back to see the changes.实际上,结果比我在本地使用 Mobx 作为数据层时更糟糕 - 在那里我必须将光标从行移开或移回以查看更改。 Here on codesandbox I can't see the changes at all.在 codeandbox 上,我根本看不到更改。

You're mutating the data , which does not force your Table to re-render.您正在改变data ,这不会强制您的 Table 重新呈现。 Your example will work if you add this.forceUpdate() before and in the end of setTimeout .如果您在setTimeout之前和之后添加this.forceUpdate() ,您的示例将起作用。 This is ugly fix, but it might help to understand the root case.这是一个丑陋的修复,但它可能有助于理解根本情况。

Better solution is to extract actions into own component with own loading state:更好的解决方案是将动作提取到具有自己loading状态的组件中:

const Actions = props => {
  const [loading, setLoading] = useState(false);
  return (
    <span>
      {loading ? (
        <Icon type="loading" spin />
      ) : (
        <a
          href="#"
          onClick={() => {
            setLoading(true);
            setTimeout(setLoading, 2000);
          }}
        >
          Reload
        </a>
      )}
    </span>
  );
};

And then your actions column become:然后您的操作列变为:

    <Column
      title="Action"
      key="action"
      render={(text, record) => <Actions />}
    />

这是一个棘手的问题,对我有用的是在执行更新表的操作之前延迟 1000 毫秒

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM