Using react-query v.3, what's the best way to get the data of a promise response of a useQuery() dependant query?
I cannot map() directly to the data response.
ref.: https://react-query.tanstack.com/guides/dependent-queries
Using react-query v.3, what's the best way to get the data of a promise response of a useQuery() dependant query?
I cannot map() directly to the data response.
ref.: https://react-query.tanstack.com/guides/dependent-queries
isSuccess: const { isSuccess, data } = useQuery(
['projects', userId],
getProjectsByUser,
{
// The query will not execute until the userId exists
enabled: !!userId,
}
)
if (isSuccess) {
return data.map(...) // <-- data is guaranteed to be defined
}
const { isSuccess, data } = useQuery(
['projects', userId],
getProjectsByUser,
{
// The query will not execute until the userId exists
enabled: !!userId,
}
)
return data?.map(...) ?? null // <-- make sure to handle fallback with ??