TanStackT
TanStack3y ago
3 replies
brilliant-lime

What is the best way to refetch with dependent queries

is there a way to also refetch the dependent query? currently, when i refetch for example the
userQuery
id does not refetch the projects.

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

const userId = user?.id

const {
  status,
  fetchStatus,
  data: projects,
} = useQuery({
  queryKey: ['projects', userId],
  queryFn: getProjectsByUser,
  enabled: !!userId,
})
Was this page helpful?