Dependent Query conditions #695
Answered
by
tannerlinsley
BlackMarq20
asked this question in
General
-
Are you able to specify a key as a dependent query? In looking at the documentation, the enabled flag is using the result of the user query, however if this query was executed in say another component, would it be possible to just specify the key? or do you need to also execute useQuery in that component? // Get the user
const { data: user } = useQuery(['user', email], getUserByEmail)
// Then get the user's projects
const { isIdle, data: projects } = useQuery(
['projects', user.id],
getProjectsByUser,
{
// `user` would be `null` at first (falsy),
// so the query will not execute until the user exists
enabled: user,
}
)
Something like this?
const { isIdle, data: projects } = useQuery(
['projects', user.id],
getProjectsByUser,
{
enabled: ['user', 'another query']
}
) |
Beta Was this translation helpful? Give feedback.
Answered by
tannerlinsley
Jul 2, 2020
Replies: 1 comment 4 replies
-
Its definitely better to have it be data driven like the example above. The one below is not supported natively by useQuery, but you could potentially use queryCache.getQueryData() for each of those checks if it’s in another component. |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
MichaelDeBoey
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Its definitely better to have it be data driven like the example above. The one below is not supported natively by useQuery, but you could potentially use queryCache.getQueryData() for each of those checks if it’s in another component.