-
In one of the spots of my code, I have a query that just fetches the list of the items. And for some reason, it allows for components to run their code resulting in runtime errors before the stuff gets fetched, while they are supposed to be suspended before the results are returned. In order for Typescript to be less strict and always assume export const useQueryData = <
Data = unknown,
Variables extends AnyVariables = AnyVariables,
>(
args: UseQueryArgs<Variables, Data>,
) => {
if (process.env.NODE_ENV === "development") {
if (args.pause) {
throw Error(
"You should not use useQueryData hook in the components that PAUSE the query as it will lead to runtime error. Use useQuery instead.",
)
}
}
const [opResult, reexecute] = useUrqlQuery<Data, Variables>(args)
// We throw instantly for ErrorBoundary to handle that. No handling in the component itself
if (opResult.error) {
throw opResult.error
}
return [opResult.data, reexecute, opResult] as [
Exclude<typeof opResult.data, undefined>,
typeof reexecute,
typeof opResult,
]
} So then I use it like const [data] = useQueryData({ query: UseItem_ItemsDocument })
const items = data.items
// ^ here I have a runtime error Despite the component that uses that being wrapped in Suspense it fails. I use Any ideas what can be wrong? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Apologies, probably it's irrelevant. Do not act just yet :) Double checking something :) |
Beta Was this translation helpful? Give feedback.
Yeah, irrelevant. Sorry :)