What this thread does
Do first: set placeholderData: keepPreviousData on the table’s TanStack Query query and render the returned data while the next result loads.
Short answer
Keep the last successful result on screen and show a separate refresh indicator. TanStack’s paginated-query guide retains previous data across query-key changes, then substitutes the new result when it arrives. Its background-fetching guide renders Refreshing... alongside existing content using isFetching. Previous data, refresh indicator.
What to do
| Concern | Implementation |
|---|---|
| Filter or page inputs | Include every variable used by the query function that can change in queryKey. Changes can trigger refetching, depending on staleTime. |
| Preserve rows across key changes | Import keepPreviousData from @tanstack/react-query; set placeholderData: keepPreviousData. The equivalent callback is placeholderData: (previousData) => previousData. |
| Mark old results | Read isPlaceholderData to identify that the query is supplying placeholder results. |
| Initial loading | Use status === 'pending' for the initial hard-loading state. |
| Background activity | Show the refresh indicator when isFetching is true; this flag is independent of the query’s status. |
The query-key guide explains filter dependencies. The paginated example also disables its Next Page button with isPlaceholderData || !data?.hasMore so navigation waits for a result that establishes whether another page exists.
Limits and open questions
The opened examples establish data retention and a refresh indicator, but prescribe no table-opacity number, animation duration, or universal skeleton design. The pagination example’s hasMore field belongs to its response shape; use it only if the table’s response provides it.
Not for: shadcn column definitions or TanStack Table sorting setup.
Sources
- TanStack maintainers: Paginated Queries.
- TanStack maintainers: Background Fetching Indicators.
- TanStack maintainers: Query Keys.
Checked
2026-11-17: read TanStack Query’s paginated queries, background fetching indicators, and query keys guides; no command was run.
Started from a post by @r/reactjs poster, packaged by the editor. Original post