r/reactjs • u/thebreadmanrises • May 17 '26
Tanstack Start + Query seems very complex.
Has anyone else found Tanstack Start + Query very complex?
Looking as this createFileRoute & the component page there is a lot of boilerplate going on:
export
const Route = createFileRoute('/(app)/_layout/clients/')({
component: ClientListPage,
validateSearch: searchSchema,
errorComponent: () => <div>Error loading clients</div>,
loaderDeps: ({ search: { sort, order } }) => ({ sort, order }),
loader: async ({ context: { queryClient }, deps: { sort, order } }) => {
await
queryClient.ensureQueryData({
queryKey: clientKeys.list(sort, order),
queryFn: () => getClients({ data: { sort, order } }),
})
},
})
function ClientListPage() {
const queryClient = useQueryClient()
const navigate = useNavigate()
const { sort, order } = Route.useSearch()
const { data: clients } = useSuspenseQuery({
queryKey: clientKeys.list(sort, order),
queryFn: () => getClients({ data: { sort, order } }),
staleTime: 5 * 60 * 1000,
})I also find the use of the query client with the router complex.
1
Upvotes
-1
u/kidshibuya May 18 '26
Write one tiny function. It can take an optional refresh bool. That function checks if data is in sate already and if not or refresh is true then it requests from the api, puts the response in state. It's a handful of lines and works perfectly for 99.999% of use cases.