How to handle errors with the `usePaginatedQuery()` React hook?
Greetings, all π I'm brand-new to the discord community, and also in fact somewhat new to Convex (two months, and overall pleased)β¦
So, my question: I'm using
usePaginatedQuery()
to load realtime chat messages powered by Convex, and am seeking guidance on error handling.
I've always got an eye towards error handling which is "extra-strength" when it comes to anything involving network operations π but am finding a lack of any mention in the usePaginatedQuery()
docs about error handling of any kind (in fact the only in-page search result for the string "error" highlights the API reference link in the docs nav π
).
For convenience: https://docs.convex.dev/database/pagination
So I'm wondering: are there any best practices that either end-users or even Convex team members have found to be especially useful and effective?
And, to piggy-back with a (100% relevant, at least!) feature request for the team: please consider adding an error
key to the hook return value.Paginated Queries | Convex Developer Hub
Load paginated queries.
16 Replies
@prometheas π₯ could you say more about what you want here? You can handle the built-in usePaginatedQuery error with an error boundary in React
This is the same way useQuery() and other query hooks work by default in the Convex React client bindings
hey @ballingt ! Sure, would be an ergonomic win to have something along the lines of react-query, with
isError: boolean
and error?: Error
keys in the object returned by the hookCool! We've got a React Query bindings actually, https://docs.convex.dev/client/tanstack-query, but it doesn't support paginated query yet. This is coming soon! See this issue https://github.com/get-convex/convex-react-query/issues/1
oh, sweeet
It's helpful to hear you want this style instead of throwing the error
i'mma subscribe to that issue -- thank you, sir!
yes, that would 100% satisfy my current scenario
It's also possible not to involve TanStack Query, and write a new usePaginatedQuery hook that returns an error objects βΒ that's provided in https://github.com/get-convex/convex-helpers/blob/main/packages/convex-helpers/README.md#richer-usequery but also without usePaginatedQuery yet.
though that issue looks untouched since its creation in mid-July
Yeah I'm about to roll back onto this project!
right on
That repo is somewhat a proof of concept, but I'm getting back to it because TanStack Start is entering alpha
well, I appreciate your jumping in and shedding light
I'm understand right that you don't want to use an error boundary, that's the main issue here?
I agree it's nice to use the TanStack Query-style hook signature
yea, man. error boundaries are our best backstop, but aren't my favorite way to handle async errors
I could imagine us adding a useQueryObject, usePaginatedQueryObject, etc. to core, but for now I want to improve the TanStack Query bindings to make that a viable option
agree with strategy there, fwiw