首页 > 解决方案 > ReactTable 和自定义服务器端数据更新

问题描述

有没有人用过这个很棒的反应组件来处理服务器端数据?

如果您不需要手动更新数据,这里给出的解决方案非常好。

我不仅需要在更改 page/pageSize/sorting/filtering 时刷新数据,而且还需要在一段时间后刷新数据,以查看数据是否已更改。

此外,我还有一个表格扩展,允许用户对所有列进行全文搜索,因此当用户更改自定义搜索框的内容时,我也需要更新数据。

标签: reactjsreact-table

解决方案


我遇到了和你一样的问题,我开始寻找 ReactJs 的异步测试,我发现这篇文章非常有用。关键部分是在 Enzyme 组件上使用“更新”方法,如下所示:

const items = ['die Straße', 'die Adresse', 'die Nationalität'];

jest.useFakeTimers();

describe('<DelayedList />', () => {
  test('it renders the items with delay', () => {
    const component = shallow(
      <DelayedList items={items} />
    );

    jest.runAllTimers();
    component.update(); // <--- force re-render of the component

    expect(component.state().currentIndex).toEqual(items.length);
    expect(component).toMatchSnapshot();
  });

有关详细信息,请参阅这篇中型文章


推荐阅读