Hey, I have a Problem with TanStackQuery and TanSt...
# javascript
h
Hey, I have a Problem with TanStackQuery and TanStackTables, When I receive an
Array
through
useQuery<Array<MyType>>()
and feed it into the TanStackTable directly everyting works, no problems. But when I filter the
Array
or convert it to a list for other reasons and then convert it back via
.toTypedArray()
the TanStackTable displays the data correctly, but it refreshes infinitely and very fast lagging the tab. I can see the constant
getXXXModel()
log messages in the console.
Copy code
previewDataQuery
  .data
  ?.filter { it.active }
  ?.toTypedArray()
Someone got a suggestion how to fix this? Edit: So the behaviour is essentially like this:
Copy code
useReactTable(data = previewData) // OK
useReactTable(data = previewData.toList().toTypedArray()) // Infinite Loop
Okay the solution is to memo the result because TanStack checks for referencial equality:
Copy code
val previewData = useMemo(previewDataQuery.data) {
  previewDataQuery.data
    ?.filter { it.active }
    ?.toTypedArray()
}
🧌 1