Extending react-query with typescript

Guys I'm just wondering if I can do something like this? import { useQuery } from "@tanstack/react-query"; export function usePaginatedQuery (other params,...[USE QUERY PARAMS]) { const query = useQuery([USE QUERY PARAMS]) } I see myself rewriting the logic for this for the entire app so I'm trying to create a custom hook for it. However, I can't find any reference on the internet on how to properly extend useQuery using typescript. My knowledge in typescript is not that deep yet to figure out this kind of things. I know this is easy enough in plain js but I want the benefits of typescript. Any help would be appreciated, TIA!
Solution:
in general you can get very far with just the queryOptions API
Jump to solution
7 Replies
Salumsu
SalumsuOP5mo ago
This is what I've come up with so far with chatgpt.
No description
Salumsu
SalumsuOP5mo ago
I just copied the types from here
No description
tylerlaws0n
tylerlaws0n5mo ago
Could you just export const usePaginatedQuery: typeof useQuery => (…?
cje
cje5mo ago
react query has a primitive for pagination, useInfiniteQuery return types are inferred
Solution
cje
cje5mo ago
in general you can get very far with just the queryOptions API
cje
cje5mo ago
i would also be surprised if you need to ever pass the queryClient to a hook manually - there's a useQueryClient to access it when you need it
Salumsu
SalumsuOP5mo ago
I also need another props so that is not what Im looking for... can you jump to a page with that? Im trying to display a table and it has pagination controls. I don't think use useInfiniteQuery would help with that. will check that out, thank you yessss, that is exactly what I was looking for! Thank you!
Want results from more Discord servers?
Add your server