useQuery
data return type is Data | undefined
when using Suspense
#654
Replies: 3 comments
-
Hi, I was wondering this myself and I think it could be possible with discriminated unions where one config type has suspense enabled and another one with suspense disabled. The only difficult part is that suspense can be enabled globally but we don't know this in the hooks. This means that you'll need to manually set the correct config type in the hooks which you'll probably don't want. It would be better that they changed automatically of course. Maybe there is an option to let the developer override some types in a declaration file so they only need to change it in 1 place? I also think there is a similar case when |
Beta Was this translation helpful? Give feedback.
-
Yes, exactly! The return type is much simpler when you have both suspense and error boundary enabled. |
Beta Was this translation helpful? Give feedback.
-
I personally also think that this would be much nicer and would help clean up code in child components even more, like Suspense mode already does so well. However I read in some issue that this was not feasible because of the fact that a query can be disabled by setting |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Describe the bug
Not sure if it's possible to fix this, but when we use suspense
{ data } = useQuery()
will never beundefined
. The return type ofdata
isData | undefined
though. Maybe we can create another type for when it's suspended? Not sure.Beta Was this translation helpful? Give feedback.
All reactions