React Router
Install
Section titled “Install”npm install @seaforms/reactpnpm add @seaforms/reactyarn add @seaforms/reactbun add @seaforms/reactAdd the form
Section titled “Add the form”There are two ways, and both put the form in your page’s HTML. Pick by who changes it:
- From the form’s file if you change the form yourself. A pull shows up in your diff, and a build never depends on Seaforms answering. It works on server-rendered and pre-rendered routes.
- Fetched at build if a client or colleague changes it. They publish in the app and your next build has it, with no file to pull or commit. It belongs on pre-rendered routes only.
Hand this to your coding agent
Read https://developer.seaforms.io/llms-full.txt. Install @seaforms/react in this React Router (Framework mode) project. Run npx seaforms login (I'll approve it in my browser), then npx seaforms pull to save my published forms in forms with their types. Then add the contact form to app/routes/contact.tsx with the Form component. Use only the components, functions and commands that file lists, and don't edit the .seaforms.json files.
Save your published forms into the project with npx seaforms pull, then import one. A new React Router project has no src folder, so they go in forms:
Directoryapp
Directoryroutes
- contact.tsx the page
- root.tsx
- routes.ts
Directoryforms
- contact.seaforms.json from
npx seaforms pull - contact.seaforms.d.ts its types
- contact.seaforms.json from
- react-router.config.ts
- seaforms.json which site this project is
import { Form } from "@seaforms/react";import contact from "../../forms/contact.seaforms.json";
export default function ContactPage() { return ( <main> <h1>Get in touch</h1> <Form schema={contact} /> </main> );}React Router renders the form into the page’s HTML, on each visit or at build, and it wakes once its script loads.
Hand this to your coding agent
Read https://developer.seaforms.io/llms-full.txt. Install @seaforms/react in this React Router (Framework mode) project. Fetch the form while the site builds with getForm from @seaforms/react/server. Its ID is <FORM_ID>. The API key is in the SEAFORMS_API_KEY environment variable: read it from there and never write a key into the code. Then show the form on app/routes/quote.tsx, calling getForm in the route's loader, and add /quote to prerender in react-router.config.ts. Use only the components, functions and commands that file lists, and don't edit the .seaforms.json files.
Make an API key for the form’s site that can only read forms, and set it where your site builds:
SEAFORMS_API_KEY=sfk_…List the page in prerender, so its loader runs while the site builds:
import type { Config } from "@react-router/dev/config";
export default { prerender: ["/quote"],} satisfies Config;import { Form } from "@seaforms/react";import { getForm } from "@seaforms/react/server";import type { Route } from "./+types/quote";
export async function loader() { const quote = await getForm("frm_7f3kq2m4xa", { apiKey: process.env.SEAFORMS_API_KEY }); return { quote };}
export default function QuotePage({ loaderData }: Route.ComponentProps) { return <Form schema={loaderData.quote} />;}React Router runs the loader once, when it builds the page, and the form goes into the page’s HTML. The key stays in the build: it’s in nothing a browser loads. Build again once a change is published: a deploy hook on your host does it in one click.
Its options, and every error that stops a build, are in the getForm reference.
Our finished look
Section titled “Our finished look”Import its stylesheet once, in your root route:
import "@seaforms/react/theme.css";See Styling for its variables, or your own classes instead.
Checked in a real build
Section titled “Checked in a real build”What this page promises is checked by our tests in real Chrome on a React Router 8.5 site in Framework mode, on all 16 templates, on a server-rendered page and on a pre-rendered one. The form is in the HTML, shows and posts without JavaScript, wakes with no hydration errors and no layout shift, and its steps work. getForm is checked in a real build with a test key, which ends up in nothing a browser loads.
ChatGPT is a trademark of OpenAI, and Claude and Claude Code are trademarks of Anthropic. Other product names and logos belong to their owners. None of them makes or endorses Seaforms. Trademarks