'SWR with material UI Data Grid
I am using SWR to get the data to populate the rows of the Data Grid
fetcherGet = (url: any) => axios.get(url).then((res: {data: any}) => res.data)
let {data: customers = []} = useSWR(
[ROUTES.GET_CUSTOMERS_BY_ROUTE],
fetcherGet
)
return (
<DataGrid rows={customers} columns={columns} />
)
The issue is that when I switch to another tab and come back to the app, SWR return an undefined so an empty array is assigned and the grid gets empty. Then the data comes and the grid gets the data again. If I keep remove [], Data Grid has an error cause undefined does not have a length attribute.
What is the best way to handle the undefined return while the data is fetched to prevent the grid to be emptied before getting the data?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
