# React

**Status: there is no `@fellowframework/react` package yet.** Fellow's pages, build pipeline and generated
client are Vue only today (see [`fellow docs vue`](/docs/vue); for Astro sites there is [`fellow docs astro`](/docs/astro)). This page says what works for a React front end now and what
is needed for a first-class adapter, so nobody builds on something that does not exist.

## What works today: Fellow as the API

A React application (Vite, Next.js, React Router) can use a Fellow application as its backend. Everything on the
server side is the same: `defineRoute` contracts, tenant isolation, permissions, validation.

| Need | How |
|---|---|
| Types for the API | `fellow openapi > openapi.json`, then any OpenAPI 3.1 generator (for example `openapi-typescript`) |
| Shared validation | Import Zod schemas from `@fellowframework/core/contracts`: it is browser-safe and has no Vue dependency |
| Sign-in from the browser | Session cookie (`POST /api/accounts/session` from `fellow make:auth`), same origin |
| Mutations with the session | Send the session's CSRF token in `x-csrf-token` (see [`fellow docs auth`](/docs/auth)) |
| Server-to-server calls | `Authorization: Bearer <token>` from `signToken`; bearer requests are exempt from CSRF |
| Errors | JSON body with a stable `code`, `message`, `requestId` and field issues on 422 (see [`fellow docs routes`](/docs/routes)) |

`<fellow-ask>` from `@fellowframework/ask` is a custom element, so it works in React as it is: import
`@fellowframework/ask/element` in a client component and write the tag ([`fellow docs knowledge`](/docs/knowledge)).

Constraints to plan for:

- **Same origin.** Fellow ships no CORS middleware, and the session cookie is `SameSite=Lax`. Serve the React
  build and the API under one origin (a reverse proxy, or copy the React build into the Fellow app's `public/`).
- **No generated React client.** `src/fellow.gen.ts` and the `api` object target `@fellowframework/vue`.
- **No React pages.** `definePage` renders Vue components; `fellow dev` and `fellow build` do not compile JSX
  pages.

## What a first-class adapter needs

The server side is ready for it: pages already speak the Inertia protocol, which `@inertiajs/react` implements.
A React adapter keeps `definePage` contracts unchanged and adds three things: the component named by `component`
resolved to a `.tsx` file, JSX pages in `@fellowframework/build`, and a generated client with the form and query
helpers as hooks. It is not available yet; the changelog will say when it is.
