Module exposing: getQueryClient, makeQueryClient
// Source: https://github.com/foxminchan/BookWorm | License: MIT | Copyright Nhan Nguyen (nguyenxuannhan407@gmail.com)
// Provided via justclaw.it.com; keep this notice with the code.
import {
QueryClient,
defaultShouldDehydrateQuery,
isServer,
} from "@tanstack/react-query";
/**
* Creates a new QueryClient instance with optimized settings for SSR.
*
* Key configurations:
* - staleTime: 60s to avoid immediate refetch on client after SSR hydration
* - Dehydrates pending queries for server streaming support
* - Does not redact errors in Next.js (Next.js handles this automatically)
*/
function makeQueryClient() {
return new QueryClient({
defaultOptions: {
queries: {
// With SSR, we usually want to set some default staleTime
// above 0 to avoid refetch
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key