Material-table: Treating error from remote data

Created on 5 Sep 2019  路  1Comment  路  Source: mbrn/material-table

I'm using promise to fetch material-table's pagination, instead of using an complete array.
It's something like that:

<MaterialTable
  title="Users"
  icons={tableIcons}
  columns={columns}
  data={
    new Promise((resolve, reject) =>  ... )
      .then(...)
      .catch(err => {
        console.log(err);
        reject(err);
      })
  detailPanel={DetailPanel}
        />

So far, so good, everything is fine.
Now I'm forcing errors, like shutting down the backend while changing the page, or messing with the query response.
But, when it catches the error, it doesn't render anything about the error, it just keeps with the circular progress animation. Does material-table have any hook for this kind of error?

ask to stackoverflow has a solution question

Most helpful comment

Hello,
i think you need to throw the error first.
```
data={
new Promise((resolve, reject) => ... )
.then(response => {
if(response.ok) return response.json() else throw response;
})
.catch(err => {
resolve({data: []}); //etc
})

>All comments

Hello,
i think you need to throw the error first.
```
data={
new Promise((resolve, reject) => ... )
.then(response => {
if(response.ok) return response.json() else throw response;
})
.catch(err => {
resolve({data: []}); //etc
})

Was this page helpful?
0 / 5 - 0 ratings