React
Build powerful multi-step forms and surveys in your React app.
Use with React
MailingListForm.tsx
// "use client";
import "formsmd/dist/css/formsmd.min.css";
import { useEffect, useRef } from "react";
import { Composer, Formsmd } from "formsmd";
const composer = new Composer({
id: "mailing-list-form",
postUrl: "/api/mailing-list",
});
composer.emailInput("email", {
question: "Join our mailing list",
description:
"Stay informed of every update that matters - we'll deliver the latest news straight to your inbox.",
required: true,
});
export default function MailingListForm() {
const containerRef = useRef(null);
useEffect(() => {
if (containerRef.current) {
const formsmd = new Formsmd(composer.template, containerRef.current, {
postHeaders: {
Authorization: `Basic ${process.env.PUBLIC_API_KEY}`,
},
});
formsmd.init();
}
}, []);
return (
<div ref={containerRef} style={{ width: "500px", height: "500px" }}></div>
);
}page.tsx
Next.js, Remix, Astro, etc., and SSR
Last updated