examples/svelte/default-query-function
| Name | Last commit message | Last commit date |
|---|---|---|
| .. | ||
README.md
TanStack Svelte 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/App.sveltedefinesdefaultQueryFn, which fetcheshttps://jsonplaceholder.typicode.complus the first element of thequeryKey, and sets it asdefaultOptions.queries.queryFnon theQueryClient.src/lib/Posts.sveltecallscreateQuerywith onlyqueryKey: ['/posts'], andsrc/lib/Post.sveltewithqueryKey: [`/posts/${postId}`]andenabled: !!postId. Neither passes aqueryFn.src/lib/Posts.sveltecallsqueryClient.getQueryData([`/posts/${post.id}`])to style links whose post is already cached.
To run this example:
npm installnpm run dev