Repository navigation
|
Is it possible to use tanstack table together with rtk-query? Has anyone here tried using tanstack table? Here is an example of how to create a table. Here are the docs for the useTable() hook used in the above example. Thanks! |
Answered by
jul6art
Nov 30, 2026
Replies: 1 comment
|
Yes, they fit well: TanStack Table is headless and only needs a
With TanStack Table v9 (the import { useCreateAtom, useSelector } from '@tanstack/react-store'
import { rowPaginationFeature, tableFeatures, useTable } from '@tanstack/react-table'
import type { PaginationState } from '@tanstack/react-table'
const features = tableFeatures({ rowPaginationFeature })
const emptyRows: Person[] = []
function PeopleTable() {
const paginationAtom = useCreateAtom<PaginationState>({ pageIndex: 0, pageSize: 20 })
const pagination = useSelector(paginationAtom, (value) => value)
const { data } = useGetPeopleQuery({ page: pagination.pageIndex, size: pagination.pageSize })
const table = useTable({
features,
columns,
data: data?.rows ?? emptyRows,
rowCount: data?.rowCount,
atoms: { pagination: paginationAtom },
manualPagination: true,
})
// ...render as in the docs
}RTK Query's |
0 replies
Answer selected by
steinarb
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, they fit well: TanStack Table is headless and only needs a
dataarray, which is what an RTK Query hook gives you. Two things to watch:data ?? []creates a new array on every render.With TanStack Table v9 (the
useTablefrom the docs you linked), adapted from its TanStack Query example: