examples/preact/default-query-function
| Name | Last commit message | Last commit date |
|---|---|---|
| .. | ||
README.md
TanStack Preact 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.complusqueryKey[0], and sets it asdefaultOptions.queries.queryFnon theQueryClient.- In
src/index.tsx,PostscallsuseQuerywith onlyqueryKey: ['/posts'], andPostwith onlyqueryKey: [`/posts/${postId}`]andenabled: !!postId. Postsalso callsqueryClient.getQueryData([`/posts/${post.id}`])to show posts that are already cached in bold green.
To run this example:
npm installnpm run dev