Open History to see the last commit
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