Install
npm install @submityourform/react
Use the hook
'use client';
import { useSubmitYourForm } from '@submityourform/react';
export default function Contact() {
const { submit, status, message, errors, reset } = useSubmitYourForm({
formKey: 'YOUR-FORM-KEY',
settings: { subject: 'New message from the website' }, // sent as _subject
});
async function onSubmit(e) {
e.preventDefault();
const form = e.currentTarget;
const result = await submit(form); // pass the form element: files and multi-selects are kept
if (result.ok) form.reset();
}
return (
<form onSubmit={onSubmit}>
<input name="name" required />
<input name="email" type="email" required />
<textarea name="message" required />
<input type="text" name="_honeypot" tabIndex={-1} autoComplete="off" style={{ display: 'none' }} aria-hidden="true" />
<button disabled={status === 'submitting'}>Send</button>
{message && <p role={status === 'error' ? 'alert' : 'status'}>{message}</p>}
{(errors ?? []).map((err) => <p key={`${err.field}-${err.code}`}>{err.field}: {err.message}</p>)}
</form>
);
}
The hook returns submit, status (idle, submitting, success or error), message, errors (field problems from validation), isSubmitting and reset. submit() accepts the form element, a FormData or a plain object, and resolves to { ok, id, held, test, code, message, errors }. A plain object is sent as JSON, so keep its values flat (strings, numbers, arrays of strings). Pass the form element when it has file inputs or multi-selects.
settings adds special fields to every submission: subject, fromName, replyTo, cc and redirect are sent as _subject, _from_name, _reply_to, _cc and _redirect. The endpoint defaults to https://app.submityourform.com/f.
Next.js
The hook runs in the browser, so in the App Router mark the component with 'use client'. Nothing else is needed: submissions go straight from the visitor's browser to SubmitYourForm, so no API route or server secret is involved.
If you'd rather submit from the server (for example a Server Action or a route handler), post JSON to https://app.submityourform.com/f with the _form_key field. Server-side submissions need a paid plan: on Free (and No-branding), requests without a browser Origin are refused with SERVER_SIDE_NOT_ALLOWED; upgrade to Growth or above, or submit from the browser instead. Alternatively, create entries with the REST API using an API key kept on the server. Never put your REST API key in browser code: the form key is the only key a public form needs.