examples/lit/default-query-function
| Name | Last commit message | Last commit date |
|---|---|---|
| .. | ||
README.md
TanStack Lit Query Default Query Function Example#
Sets a default queryFn on the QueryClient that builds the request URL from the query key, so each query only passes a queryKey.
How it works#
src/main.tsdefinesdefaultQueryFn, which fetcheshttps://jsonplaceholder.typicode.complusqueryKey[0], and sets it asdefaultOptions.queries.queryFnon theQueryClientpassed to aQueryClientProvidersubclass.src/post-list.tscallscreateQueryControllerwith onlyqueryKey: ['/posts'], and callsuseQueryClient().getQueryData([`/posts/${post.id}`])to show posts that are already cached in bold green.src/post-detail.tscallscreateQueryControllerwith onlyqueryKey: [`/posts/${this.postId}`]andenabled: !!this.postId.
To run this example:
npm installnpm run dev