Best way to use useInfiniteQuery with typescript #866
-
It is so frustrating to new users like me to use useInfiniteQuery with Typescript. So I implemented as an example for this: https://codesandbox.io/s/react-query-useinfinitequery-be62c?file=/src/App.tsx Do you think it is good for example of useInfiniteQuery with Typescript? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
Completely agree that useInfiniteQuery has frustrating types. I was able to switch to tsnext (as mentioned in the docs https://react-query.tanstack.com/docs/typescript) and I haven't had to specify anything for useInfiniteQuery. The downside is useMutation returns unknown for errors by default, so you either have to specify that type or cast it. |
Beta Was this translation helpful? Give feedback.
-
I also had a rough time implementing the infiniteQuery. The example is quite vague in terms of variables and the main idea. I think the problem is the architecture of the API. Limiting/ Skipping base API would be more explanatory. |
Beta Was this translation helpful? Give feedback.
-
Here is an example using |
Beta Was this translation helpful? Give feedback.
-
Any more ideas on this topic? |
Beta Was this translation helpful? Give feedback.
Here is an example using
tsnext
with the HackerNews API, fetching items in groups of five: https://codesandbox.io/s/confident-dawn-67yb2?file=/src/App.tsx