oag-react 0.1.1

React/SWR client generator for oag
Documentation

oag-react

React/SWR hooks generator for OpenAPI 3.x specs.

Extends the TypeScript generator with React-specific code: SWR hooks for data fetching and a context provider for the API client.

Generated files

Everything from oag-typescript plus:

File Description
hooks.ts Typed React hooks for every operation
provider.ts ApiProvider context component and useApiClient() hook
index.ts Enhanced barrel exports (includes hooks and provider)

Hook types

HTTP method Hook pattern Library
GET useSWR query hook SWR
POST, PUT, DELETE, PATCH useSWRMutation mutation hook SWR
SSE streaming Custom hook with useState + useCallback React

Usage pattern

import { ApiProvider, useListPets } from "./generated";

function App() {
  return (
    <ApiProvider baseUrl="https://api.example.com">
      <PetList />
    </ApiProvider>
  );
}

function PetList() {
  const { data, error, isLoading } = useListPets();
  // ...
}

Depends on

  • oag-core — parser, IR, and CodeGenerator trait
  • oag-typescript — base TypeScript generation (React generator calls it internally)

Part of oag