initTsrReactQuery (v5/init-tsr-react-query.tsx)

ts-rest · libs/ts-rest/react-query-v5/src/v5/init-tsr-react-query.tsx · typescript · MIT
ui

Generates type-safe React Query hooks and a provider from a ts-rest contract to streamline API data fetching in React applications.

// 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 { AppRouter, ClientArgs } from '@ts-rest/core';
import { QueryClient } from '@tanstack/react-query';
import * as React from 'react';
import { useTsrQueryClient } from './internal/use-tsr-query-client';
import { initHooksContainer, initQueryClient } from './internal/create-hooks';
import { TsRestInnerProvider } from './internal/provider-inner';

export const initTsrReactQuery = <
  TContract extends AppRouter,
  TClientArgs extends ClientArgs,
>(
  contract: TContract,
  clientOptions: TClientArgs,
) => {
  return {
    ReactQueryProvider: function ({ children }: React.PropsWithChildren) {
      return (
        <TsRestInnerProvi

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

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

Get a free API key