TanStackT
TanStack5mo ago
2 replies
primary-violet

Error handling with `queryClient.fetchQuery`

Hi! I have a
useQuery
that used to manage fetching events that occur between two dates. The previous implementation expected external state, so this was no problem before. However, we are migrating to a different library, and it has a very different structure.

It instead expects me to handle (start: Date, end: Date, onSuccess: (events: ...[]) => void.
Most of the query hook is easily transferable to queryClient.fetchQuery (select, success handling, endpoint etc.). However, One thing I lose out on is the query.isError functionality, which is kind of a shame, because I know that this query can fail due to reasons that the user should know about.

Maybe it's a mutation I'm looking for? I'm only reading data, so I'm not sure if I sacrifice some other feature by using that. Do you have suggestions?
Was this page helpful?