Astro
Install
Section titled “Install”Add Astro’s React integration if your project doesn’t have it, then the package:
npx astro add reactnpm 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 your next build has it, 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 Astro 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 src/pages/contact.astro with the Form component and client:load. 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:
Directorysrc
Directoryforms
- contact.seaforms.json from
npx seaforms pull - contact.seaforms.d.ts its types
- contact.seaforms.json from
Directorypages
- contact.astro the page
- astro.config.mjs
- seaforms.json which site this project is
---import { Form } from "@seaforms/react";import contact from "../forms/contact.seaforms.json";---
<h1>Get in touch</h1><Form schema={contact} client:load />Hand this to your coding agent
Read https://developer.seaforms.io/llms-full.txt. Install @seaforms/react in this Astro 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 src/pages/quote.astro with client:load, reading the key through astro:env. 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_…Keep it a secret with astro:env, which reads it while the build runs and never writes it into the built code (import.meta.env would):
import { defineConfig, envField } from "astro/config";import react from "@astrojs/react";
export default defineConfig({ integrations: [react()], env: { schema: { SEAFORMS_API_KEY: envField.string({ context: "server", access: "secret" }) }, },});---import { Form } from "@seaforms/react";import { getForm } from "@seaforms/react/server";import { SEAFORMS_API_KEY } from "astro:env/server";
const quote = await getForm("frm_7f3kq2m4xa", { apiKey: SEAFORMS_API_KEY });---
<Form schema={quote} client:load />Astro fetches the form when it builds the page, so build again once a change is published: a deploy hook on your host does it in one click. Keep the form on a page Astro builds ahead, which is the default. A page rendered on each visit (export const prerender = false) would ask Seaforms every time.
Its options, and every error that stops a build, are in the getForm reference.
Which directive
Section titled “Which directive”Astro renders the form into the page’s HTML whatever you choose. The directive decides when it wakes up.
| Directive | When to use it |
|---|---|
client:load |
The default. It wakes as the page loads. Use it on every page of a form that offers Save and finish later: the emailed link’s key leaves the address bar only once the script runs. |
client:visible |
A form further down the page. It wakes when it scrolls into view. |
none, with static |
A page that loads no script. Every step shows on one page, with one Send at the end, and the thank-you comes from our server. See Without JavaScript. |
<Form schema={contact} client:visible /><Form schema={contact} static />Our finished look
Section titled “Our finished look”Import it once, in a layout:
---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 (in the HTML, works before JavaScript, no shift, keyboard and screen readers) is checked by our tests in real Chrome on an Astro site, 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