Skip to content

Next.js

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.
  • Fetched at build if a client or colleague changes it. They publish in the app and Next.js picks it up, with no file to pull or commit.

Hand this to your coding agent

Read https://developer.seaforms.io/llms-full.txt.
Install @seaforms/react in this Next.js (App Router) project. Run npx seaforms login (I'll approve it in my browser), then npx seaforms pull to save my published forms in src/forms with their types.
Then add the contact form to app/contact/page.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:

  • Directoryapp
    • Directorycontact
      • page.tsx the page
    • layout.tsx
  • Directorysrc
    • Directoryforms
      • contact.seaforms.json from npx seaforms pull
      • contact.seaforms.d.ts its types
  • seaforms.json which site this project is
app/contact/page.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>
);
}

Form is a client component, so this server page uses it as it is. Next.js renders the form into the page’s HTML, and it wakes once its script loads. @/forms is your src/forms folder through the @/* path Next.js sets up in tsconfig.json; use a relative import if your project has no such path.

Import its stylesheet once, in your root layout:

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

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

Use onSubmitted in a client component of your own to do something once the answers are stored:

app/contact/contact-form.tsx
"use client";
import { useRouter } from "next/navigation";
import { Form } from "@seaforms/react";
import contact from "@/forms/contact.seaforms.json";
export function ContactForm() {
const router = useRouter();
return <Form schema={contact} onSubmitted={() => router.refresh()} />;
}

Most forms need nothing here: the thank-you shows in the form’s own space, and a redirect after Send is a setting in the app.

What this page promises (in the HTML, works before JavaScript, no shift) is checked by our tests in a real Next.js build, on all 16 templates.

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