Material-table: endless loading/spinning when using function for data (remote data)

Created on 9 Dec 2019  路  8Comments  路  Source: mbrn/material-table

the table rerenders/spinns endless when using a fuction for data instaed of a preloaded object.

  • Not matter if I call resolve or reject.

https://codesandbox.io/s/material-demo-yvqym?fontsize=14&hidenavigation=1&theme=dark

wontfix

Most helpful comment

Is there any news about this? I am having the same issue and as for my current solution is accessing the table ref in my .catch and call the setState manually to stop the loading animation,

.catch(error => { tableRef.current.setState({ isLoading: false }); console.log('ERROR ', error); });

All 8 comments

In your sandbox the query string is the URL to your sandbox. Did you mean to query an API endpoint instead?

In your sandbox the query string is the URL to your sandbox. Did you mean to query an API endpoint instead?

Right, it should be an API endpoint when the code is really used. But in the demo case it does't matter because the response is not used. I could also have used "http://www.google.com". It simply needs to be a successfull fetch to demonstrate.

We're getting this same issue in our project. The table is given a function that returns a promise, and it can fetch data normally just fine. But if the promise fails, the table isLoading state stays as true.

I can tell the promise is failing because it will execute a .catch if I put one in there

I think the problem is in the onQueryChange function in material-table.js.

Potential solution:

onQueryChange = (query, callback) => {
  query = { ...this.state.query, ...query };

  this.setState({ isLoading: true }, () => {
    this.props
      .data(query)
      .then(result => {
        query.totalCount = result.totalCount;
        query.page = result.page;
        this.dataManager.setData(result.data);
        this.setState(
          {
            isLoading: false,
            ...this.dataManager.getRenderState(),
            query,
          },
          () => {
            callback && callback();
          },
        );
      })
      .catch(reason => {
        this.setState({ isLoading: false });
      });
  });
};

Is there any news about this? I am having the same issue and as for my current solution is accessing the table ref in my .catch and call the setState manually to stop the loading animation,

.catch(error => { tableRef.current.setState({ isLoading: false }); console.log('ERROR ', error); });

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You can reopen it if it required.

Please don't close this issue

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You can reopen it if it required.

Was this page helpful?
0 / 5 - 0 ratings