Next.js
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.
- 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
- contact.seaforms.json from
- 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> );}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.
Hand this to your coding agent
Read https://developer.seaforms.io/llms-full.txt. Install @seaforms/react in this Next.js (App Router) 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/quote/page.tsx, checking for a newly published version at most once an hour. 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_…import { Form } from "@seaforms/react";import { getForm } from "@seaforms/react/server";
export default async function QuotePage() { const quote = await getForm("frm_7f3kq2m4xa", { apiKey: process.env.SEAFORMS_API_KEY, fetchInit: { next: { revalidate: 3600, tags: ["seaforms:frm_7f3kq2m4xa"] } }, }); return <Form schema={quote} />;}revalidate: 3600: the page is built ahead, then checks for a newly published version at most once an hour. If Seaforms can’t be reached then, Next.js keeps the page it has.- A tag lets your own route handler or server action refresh it sooner, with
revalidateTag("seaforms:frm_7f3kq2m4xa", "max"). - A static export (
output: "export") gets the form at eachnext build.
With Cache Components (cacheComponents: true), call getForm inside a cached function. Without one, Next.js stops the build (“uncached data during prerendering”), and wrapping the form in <Suspense> instead would draw a placeholder before it, which moves the page.
import { cacheLife, cacheTag } from "next/cache";import { Form } from "@seaforms/react";import { getForm } from "@seaforms/react/server";
async function quoteForm() { "use cache"; cacheLife("hours"); cacheTag("seaforms:frm_7f3kq2m4xa"); return getForm("frm_7f3kq2m4xa", { apiKey: process.env.SEAFORMS_API_KEY });}
export default async function QuotePage() { return <Form schema={await quoteForm()} />;}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 layout:
import "@seaforms/react/theme.css";See Styling for its variables, or your own classes instead.
When it’s sent
Section titled “When it’s sent”Use onSubmitted in a client component of your own to do something once the answers are stored:
"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.
Checked in a real build
Section titled “Checked in a real build”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.
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