prometheas πŸ”₯
prometheas πŸ”₯β€’5mo ago

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.
16 Replies
ballingt
ballingtβ€’5mo ago
@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
prometheas πŸ”₯
prometheas πŸ”₯OPβ€’5mo ago
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 hook
ballingt
ballingtβ€’5mo ago
Cool! 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
prometheas πŸ”₯
prometheas πŸ”₯OPβ€’5mo ago
oh, sweeet
ballingt
ballingtβ€’5mo ago
It's helpful to hear you want this style instead of throwing the error
prometheas πŸ”₯
prometheas πŸ”₯OPβ€’5mo ago
i'mma subscribe to that issue -- thank you, sir! yes, that would 100% satisfy my current scenario
ballingt
ballingtβ€’5mo ago
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.
prometheas πŸ”₯
prometheas πŸ”₯OPβ€’5mo ago
though that issue looks untouched since its creation in mid-July
ballingt
ballingtβ€’5mo ago
Yeah I'm about to roll back onto this project!
prometheas πŸ”₯
prometheas πŸ”₯OPβ€’5mo ago
right on
ballingt
ballingtβ€’5mo ago
That repo is somewhat a proof of concept, but I'm getting back to it because TanStack Start is entering alpha
prometheas πŸ”₯
prometheas πŸ”₯OPβ€’5mo ago
well, I appreciate your jumping in and shedding light
ballingt
ballingtβ€’5mo ago
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
prometheas πŸ”₯
prometheas πŸ”₯OPβ€’5mo ago
yea, man. error boundaries are our best backstop, but aren't my favorite way to handle async errors
ballingt
ballingtβ€’5mo ago
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
prometheas πŸ”₯
prometheas πŸ”₯OPβ€’5mo ago
agree with strategy there, fwiw

Did you find this page helpful?