Skip to content

React Router

Terminal window
npm install @seaforms/react

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
  • react-router.config.ts
  • seaforms.json which site this project is
app/routes/contact.tsx
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.

Import its stylesheet once, in your root route:

app/root.tsx
import "@seaforms/react/theme.css";

See Styling for its variables, or your own classes instead.

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.

Was this helpful?

Your answer goes straight to the person who wrote it.

Thanks. We read every note and update the article.

Thanks, that helps us keep these useful.

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