Call useQuery that depends on data of other useQuery #2488
Unanswered
daniel-kocsis88
asked this question in
Q&A
Replies: 1 comment
-
I solved it with merging the two custom query hooks into one as explained it here: export default function useFetchSingleArticleAndUser(articleId: string) {
const articleQueryResult = useQuery<ArticleResponse>([ 'article', articleId ], () => getArticleDetails(articleId) );
const userId = articleQueryResult?.data?.sellerId;
const userQueryResult = useQuery<GetUserResponse>([ 'user', userId ], () => getUserInfo(userId),
{
enabled: !!userId,
},
);
return [ articleQueryResult, userQueryResult ];
} and I use it like this: const [article, user] = useFetchSingleArticleAndUser(articleId); |
Beta Was this translation helpful? Give feedback.
0 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.
-
Hi All,
I am trying to call a useQuery depending of the data of an other useQuery with custom hooks.
the useFetchUserInfo looks as following:
When I am trying to call useFetchUserInfo I am getting the error :
Argument of type 'string | undefined' is not assignable to parameter of type 'string'
Can someone tell me a nice way of solving this? Or should modify the query and the axios call param to type string | undefined?
thanks
Beta Was this translation helpful? Give feedback.
All reactions