Display skeleton rows during initial load #2386
-
Hi! I want to display an arbitrary number of rows whilst fetching the first page. Here's what I got: Visually it is what I want. But the code doesn't seem any good. {loading &&
Array.from({ length: skeletonRows }).map(() => {
return headerGroups.map(headerGroup => (
<tr {...headerGroup.getHeaderGroupProps()}>
{headerGroup.headers.map(column => (
<td {...column.getHeaderProps()}>
<Skeleton />
</td>
))}
</tr>
))
})} Does anyone have a better approach to this? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 16 replies
-
Hi, Recently I had added Skeleton loading to my table. First I attempted what you're doing but I quickly went ahead with other approach. The idea is to change the data & columns array passed to useTable if the content is loading. The following code create 30 rows (you can change according to your requirement) with empty data, and replace each cell with Skeleton component. const Table = (columns, data) => {
...
const tableData = React.useMemo(
() => (loading ? Array(30).fill({}) : data),
[loading, data]
);
const tableColumns = React.useMemo(
() =>
loading
? columns.map((column) => ({
...column,
Cell: <Skeleton />,
}))
: columns,
[loading, columns]
);
useTable({ columns: tableColumns, data: tableData });
...
} |
Beta Was this translation helpful? Give feedback.
-
Unfortunately this give me issues with Here is how I'm using with ShadCN
|
Beta Was this translation helpful? Give feedback.
Hi,
Recently I had added Skeleton loading to my table. First I attempted what you're doing but I quickly went ahead with other approach.
The idea is to change the data & columns array passed to useTable if the content is loading. The following code create 30 rows (you can change according to your requirement) with empty data, and replace each cell with Skeleton component.
The good thing is your column headers/footers are intact.