Docs React & Next.js

React & Next.js

POST JSON from a component with fetch and handle the response yourself.

The same endpoint accepts JSON, which suits single-page apps: post with fetch, read the JSON response, and render your own success state.

React
async function handleSubmit(event) {
  event.preventDefault();
  const form = new FormData(event.currentTarget);

  const response = await fetch("https://useformy.net/f/your-form", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify(Object.fromEntries(form))
  });

  const result = await response.json();

  if (result.ok) {
    setStatus("sent");
  } else {
    setStatus("error"); // result.error is a machine-readable code
  }
}
  • Successful submissions return { "ok": true, "submissionId": "…" }.
  • Errors return proper status codes — 403 for disabled forms or blocked domains, 429 when a plan limit is reached — with { "ok": false, "error": "…", "message": "…" }.
  • CORS is enabled, so browser posts work from any origin you allow.