getQueryClient (react-query-utils/get-query-client.ts)

ts-rest · apps/example-next/app/react-query-utils/get-query-client.ts · typescript · MIT
ui

Creates and manages a React Query client instance for server and browser environments.

// Source: https://github.com/ts-rest/ts-rest | License: MIT | Copyright 2022 Oliver Butler
// Provided via justclaw.it.com; keep this notice with the code.
import {
  QueryClient,
  defaultShouldDehydrateQuery,
  isServer,
} from '@tanstack/react-query';
import { cache } from 'react';

function makeQueryClient(streamPendingQueries = false) {
  return new QueryClient({
    defaultOptions: {
      queries: {
        staleTime: 60 * 1000,
      },

      ...(streamPendingQueries
        ? {
            dehydrate: {
              // include pending queries in dehydration
              shouldDehydrateQuery: (query) => {
                return (
                  defaultShouldDehydrateQuery(query) ||
                  query.state.status === 'pending'
                );
              },
        

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key