Skip to content

Limitations of useSuspenseQuery hook #6327

Answered by TkDodo
krisko4 asked this question in Q&A
Discussion options

You must be logged in to vote

Thanks for the feedback 🙏. Let me try to address them one by one:

(in most cases, my request needs some data received from another request in order to execute)

Dependent Queries work out of the box with suspense, because the component suspends in between 😅 . The example from the docs simply becomes:

const { data: user } = useSuspenseQuery({
  queryKey: ['user', email],
  queryFn: getUserByEmail,
})

// no optional chaining needed because user is guaranteed to be defined here
const userId = user.id

// No need for enabled: !!userId
const {
  status,
  fetchStatus,
  data: projects,
} = useSuspenseQuery({
  queryKey: ['projects', userId],
  queryFn: getProjectsByUser,
})

This is actually…

Replies: 5 comments 14 replies

Comment options

You must be logged in to vote
1 reply
@krisko4
Comment options

Answer selected by krisko4
Comment options

You must be logged in to vote
2 replies
@TkDodo
Comment options

@krisko4
Comment options

Comment options

You must be logged in to vote
5 replies
@TkDodo
Comment options

@timsofteng
Comment options

@TkDodo
Comment options

@timsofteng
Comment options

@TkDodo
Comment options

Comment options

You must be logged in to vote
5 replies
@TkDodo
Comment options

@patricklafrance
Comment options

@TkDodo
Comment options

@patricklafrance
Comment options

@alyyousuf7
Comment options

Comment options

You must be logged in to vote
1 reply
@TkDodo
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
6 participants