A contact form built with Next.js 16 + React 19 that sends submissions to your inbox through StaticForms.dev. There's no backend to write or host.
📖 Step-by-step tutorial: Using Static Forms with Next.js: A Complete Guide on the StaticForms blog.
- App Router with React Server Components
- Client component (
"use client") for the form useStatefor form status- CSS Modules
- Turbopack dev server (default in Next.js 16)
- Loading, success and error states
- Shared styling with every other example in this repo
# From the monorepo root
pnpm install
cp apps/next-example/env.example apps/next-example/.env.local
# Add your API key to the new file, then:
pnpm dev:nextThe app runs on http://localhost:3000.
| Variable | Description |
|---|---|
NEXT_PUBLIC_STATICFORMS_API_KEY |
Your StaticForms.dev API key. Get one free at staticforms.dev. |
Locally, put it in .env.local. On Vercel, the deploy button asks for it; you can also add it later under Settings → Environment Variables.
The env file keeps your key out of git. Like the hidden
apiKeyfield in a plain HTML form, the key is still visible in the browser once the site is deployed.
Click Deploy with Vercel above. Vercel copies this repository into your account, sets the project's Root Directory to apps/next-example and asks for NEXT_PUBLIC_STATICFORMS_API_KEY.
vercel.json in this folder installs only this example's dependencies from the monorepo. Output: Hybrid (Vercel Next.js runtime).
To deploy manually, import the repository at vercel.com/new, set Root Directory to apps/next-example, add the environment variable, and deploy.
| Path | Purpose |
|---|---|
src/app/page.tsx |
Home page |
src/app/layout.tsx |
Root layout and metadata |
src/components/ContactForm.tsx |
Contact form (client component) |
src/components/ContactForm.module.css |
Form styles |
vercel.json |
Vercel deployment settings |
env.example |
Environment variable template |
The form POSTs JSON to the StaticForms API:
POST https://api.staticforms.dev/submit
Content-Type: application/json
{
"apiKey": "YOUR_API_KEY",
"name": "Jane Doe",
"email": "jane@example.com",
"message": "Hello!",
"replyTo": "@",
"subject": "New Contact Form Submission"
}"replyTo": "@" sets the reply-to address to the sender's email. The API responds with { "success": true }, or with { "success": false, "message": "..." } when something goes wrong.
From the StaticForms blog:
- Using Static Forms with Next.js: A Complete Guide
- Next.js contact form with document upload
- Adding ALTCHA captcha to a Next.js form
- All StaticForms tutorials and guides
Docs:
MIT