Replies: 1 comment 3 replies
-
you pretty much want this:
then use it in components as you like:
|
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Description
In the recent versions of react-query, the ability to set suspense: true | false is deprecated, requiring the use of
useSuspenseQuery
for suspense-enabled queries. This change poses a challenge in scenarios where suspense needs to be optional.Steps to reproduce
In our current implementation, each API call is linked to a single React-Query hook, encapsulated within a function. This function can be invoked from multiple components. However, not all of these components require or support suspense.
Expected behavior
The ideal solution would allow a single query hook to dynamically handle both suspense and non-suspense scenarios without duplicating requests or hooks.
Current Workaround
Currently, it seems necessary to duplicate each request: one using
useQuery
and another usinguseSuspenseQuery
. This approach is not optimal, as it leads to redundant code and potential maintenance issues.Question
Is there an alternative approach or best practice to handle this scenario where suspense can be optionally applied within the same query hook, depending on the component it is used in?
Additional Context from Recent PR
I noticed that the removal of suspense as a configurable option seems to be a workaround taken from this PR: 6ee06719aedbf210d9c336b039f40b9667de4da0. This PR may provide some background on the current issue and decision-making process.
TanStack Query version
5.17.8
TypeScript version
4.8.3
Beta Was this translation helpful? Give feedback.
All reactions