Infinite loop when using table with async data #5900
Replies: 2 comments
|
https://tanstack.com/table/latest/docs/faq#how-do-i-stop-infinite-rendering-loops |
0 replies
|
What usually causes this in TanStack Table is not the async fetch itself, but an unstable reference being passed into Two common culprits: // bad: creates a new array every render while data is undefined
const data = query.data ?? []and columns that are recreated with changing deps. A stable version looks like this: const EMPTY: RowType[] = []
function MyTable() {
const { data = EMPTY } = useQuery(...)
const columns = useMemo(() => [
columnHelper.accessor('name', { header: 'Name' }),
], [])
const table = useReactTable({ data, columns, getCoreRowModel: getCoreRowModel() })
}Why does So I'd treat the empty check as a clue, not the final solution. The real fix is:
|
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hey @KevinVandy First of all, thank you for this amazing library it's been a game-changer for our data-heavy applications! 🙌
Problem Statement
I encountered an infinite loop issue when using the table with async data fetched via TanStack Query and wanted to confirm if this is expected behaviour or if there's a better solution.
Reproduction Scenario:
And also wrapped columns into the useMemo but still goes on an infinity loop.
Question
All reactions