How to type a helper function to standardise loading and error states with a useQuery call?
I am trying to standardize handling of error and loading states. I'd like to have one function/component that can handle what to do in those cases, and otherwise passes
data
to a function to render whatever is the happy path.
So something like this:
I'm struggling to type this in a way that the renderData
function has the structure of data
inferred by Typescript. I have looked at AppRouterLike
, QueryLike
and friends but can't get it to work. Would love some assistance, in the meantime I'll keep bashing my head against it. Here's a not-working example, in which data
is typed as any
and in the render
function TS thinks data
could be undefined
Solution:Jump to solution
In case it helps anyone, this seems to work
```ts
export function RenderQuery<
T extends QueryLike,...
1 Reply
Solution
In case it helps anyone, this seems to work
Called like