examples/vue/dependent-queries
| Name | Last commit message | Last commit date |
|---|---|---|
| .. | ||
README.md
TanStack Vue Query Dependent Queries Example#
A query that waits for another query's result, with skipToken as its queryFn until the author ID is known.
How it works#
src/services/posts/queries.tsdefinespostsQueries.list()andpostsQueries.detail(id),queryOptionsfactories keyed by['posts', 'list']and['posts', 'detail', id].src/services/authors/queries.tsdefinesauthorsQueries.detail(id), which usesskipTokenas thequeryFnwhileidisundefined.src/PostDetail.vueloads the post withuseQuery(() => postsQueries.detail(props.postId)), derivesauthorIdfrompost.value?.userIdwithcomputed, and passes it to a seconduseQuery. The author query runs only after the post has arrived, and the author name appears next to the title.src/PostList.vuereads the list withuseQuery(postsQueries.list())and marks a post as visited whenqueryClient.getQueryData(postsQueries.detail(item.id).queryKey)returns data.
To run this example:
npm installnpm run dev