examples/solid/default-query-function
| Name | Last commit message | Last commit date |
|---|---|---|
| .. | ||
README.md
TanStack Solid 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/index.tsxdefinesdefaultQueryFn, which fetcheshttps://jsonplaceholder.typicode.complus the first element of thequeryKey, and sets it asdefaultOptions.queries.queryFnon theQueryClient.- The
Postscomponent callsuseQuerywith onlyqueryKey: ['/posts'], and thePostcomponent withqueryKey: [`/posts/${props.postId}`]andenabled: !!props.postId. Neither passes aqueryFn. - The
Postslist callsqueryClient.getQueryData([`/posts/${post.id}`])to style links whose post is already cached.
To run this example:
npm installnpm run dev