Skip to main content
This example demonstrates integration with TanStack Query (React Query) for powerful data fetching, caching, and state management in React applications.

Configuration

OpenAPI TypeScript Config

Create openapi-ts.config.ts in your project root:
openapi-ts.config.ts
Key features:
  • @tanstack/react-query plugin generates hooks and options
  • @hey-api/client-fetch for Fetch API client
  • instance: true creates SDK instance

Package Dependencies

package.json

Application Setup

Main Entry Point

Configure the QueryClient and set up the global client:
src/main.tsx

Usage

Component with Queries and Mutations

src/App.tsx

Generated Helpers

The @tanstack/react-query plugin generates several helpers:

Query Options

Mutation Helpers

Key Features

Type Safety

All queries and mutations are fully typed:

Schema Validation

Use generated schemas for runtime validation:

Client Interceptors

Add middleware for authentication and logging:

Running the Example

1

Clone the repository

2

Install dependencies

3

Run the React Query example

4

Open in browser

Navigate to http://localhost:5173

Full Example

View the complete example in the repository: React Query Example on GitHub

Learn More

TanStack Query Plugin

Client Configuration

SDK Plugin

Examples Overview