Relationship between data existence guarantees in useSuspenseQuery
and the select
option
#7796
-
Let's take a look at the example below. function Page() {
const { data } = useSuspenseQuery({
queryKey: ['someKey'],
queryFn: () => 'data',
select: queryData => {
if (queryData) {
throw new Error('error');
}
return queryData;
}
});
return (
<div>
Data: {String(data)} {/* Data: undefined */}
</div>
);
} The return type of Is this type structure intended? If it is intended, I'm also wondering in what sense we should understand that the return type of FYI
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
not sure why you would throw an error in So please show a runnable reproduction where data is actually undefined in the component because I don't think that's what really happens. |
Beta Was this translation helpful? Give feedback.
Thanks for the example.
it's wrapped in a try/catch that catches the error and then subsequently sets the query state to error:
query/packages/query-core/src/queryObserver.ts
Lines 544 to 549 in 81e1f2c
error boundary handling is done on component level, so it should work the same as if the queryFn returned a rejected promise.
So I looked into it a bit and found out what the problem is.
select
runs on observer level - each useQuery instance can have its own transformation. In your scenario, the query itself that is s…