Skip to content
Wrenform

Contact forms / React

React contact form without a backend

One React component that posts with fetch and shows the result in place. No server, no API route, no email package.

Why React needs a form backend

A React app built with Vite, Lovable or Bolt runs in the visitor's browser. There is no server in the project to receive a contact form, and an email API can't be called from the browser without exposing its secret key.

The usual fix is a serverless function or an edge function that holds the key, validates the input, fights spam and calls the email service. That is a second deployment for one form.

With Wrenform the component posts straight to your endpoint. The form ID is public by design, so it can sit in client code, and Allowed origins stop other sites from using it. We store each submission, filter spam and email your recipients.

The prompt

Replace YOUR_FORM_ID with the ID of your form. The component sends FormData with Accept: application/json, so the answer is JSON: { "ok": true } on success, or an error with a stable code.

// src/ContactForm.jsx (React + Vite, also Lovable and Bolt projects)
import { useState } from "react";

export default function ContactForm() {
  const [status, setStatus] = useState("idle");

  async function onSubmit(e) {
    e.preventDefault();
    const form = e.currentTarget;
    setStatus("sending");
    try {
      const res = await fetch("https://wrenform.com/f/YOUR_FORM_ID", {
        method: "POST",
        headers: { Accept: "application/json" },
        body: new FormData(form),
      });
      setStatus(res.ok ? "sent" : "error");
      if (res.ok) form.reset();
    } catch {
      setStatus("error");
    }
  }

  return (
    <form onSubmit={onSubmit}>
      <label>Name <input type="text" name="name" autoComplete="name" required /></label>
      <label>Email <input type="email" name="email" autoComplete="email" required /></label>
      <label>Message <textarea name="message" required /></label>
      <input type="text" name="_honey" style={{ display: "none" }} tabIndex={-1} autoComplete="off" />
      <button type="submit" disabled={status === "sending"}>Send</button>
      <p role="status">
        {status === "sent" && "Thanks, your message was sent."}
        {status === "error" && "Something went wrong. Please try again."}
      </p>
    </form>
  );
}

Steps

  1. Create a form (free) and copy its form ID. No account yet? Ask your AI tool to create a quick form with framework: "react": one request returns your endpoint and a ready snippet. Click Confirm in the email from Wrenform, and messages start arriving.
  2. Save the component as src/ContactForm.jsx (or .tsx) and replace YOUR_FORM_ID, or build the URL from import.meta.env.VITE_WRENFORM_ID.
  3. Render <ContactForm /> on your contact page. With React Router, give it its own /contact route.
  4. Deploy, and add your site to Allowed origins.

Spam handling

Spam filtering is on for every form, with no CAPTCHA: a hidden honeypot field, a timing check, rate limits per visitor, and a content score for links, keywords and gibberish. Spam goes to a separate tab and is never emailed. See how spam filtering works.

Rate limits and spam rules run on our side, so the component needs no extra code for them. When a visitor sends too often, the answer is a 429 with a Retry-After header; the component shows its error line, and you can read the JSON code for a more precise message. Every code is listed in errors.

Deployment notes

  • Netlify. Deploy as usual. Netlify only processes forms that carry its own netlify or data-netlify attribute, so it leaves this form alone and the browser posts it to Wrenform. Add your netlify.app address and your custom domain to Allowed origins.
  • Vercel. Nothing to configure. The React build stays static; you don't need a serverless function for the form. Add your production domain to Allowed origins. Preview deployments get their own addresses, so leave the list empty while you test them, or add each one.
  • Cloudflare Pages. No Pages Function needed. Add your pages.dev address and your custom domain to Allowed origins. If you set a Content-Security-Policy header, add form-action https://wrenform.com.
  • GitHub Pages. GitHub Pages serves static files only, which is all this form needs. Add https://<user>.github.io (or your custom domain) to Allowed origins. The origin is the host only, without the repository path.

The no-JavaScript version

Don't need the inline result? A plain form with action and method="POST" works with no handler at all. The browser posts the form, and the visitor lands on our thank-you page, or on your own page if you set Redirect to in the form's settings. See redirects.

<form action="https://wrenform.com/f/YOUR_FORM_ID" method="POST">
  <label>Name <input type="text" name="name" autoComplete="name" required /></label>
  <label>Email <input type="email" name="email" autoComplete="email" required /></label>
  <label>Message <textarea name="message" required /></label>
  <input type="text" name="_honey" style={{ display: "none" }} tabIndex={-1} autoComplete="off" />
  <button type="submit">Send</button>
</form>

FAQ

Can a React app send a contact form without a backend?
Yes. The component posts from the browser to Wrenform, which stores the message and emails you. Your app stays a static build.
Should the form be controlled with useState for every field?
You can, but you don't need to. The component reads the inputs with FormData when the form is sent, so each input only needs a name.
Does it work in Lovable and Bolt projects?
Yes. Both generate React and Vite projects, so the component works as is. Tell the tool not to add an edge function or an email package for the form.
Where do I keep the form ID?
In the component, or in VITE_WRENFORM_ID in .env. It is not a secret; allowed origins protect the form.
Does it work with npm run dev?
Yes. Leave allowed origins empty while you test, or add http://localhost:5173.

Next steps