All guides

React guide

React contact form that emails you, no backend

A React app on a static host has nowhere to send form data. This component posts it to Formcrate, which filters spam, emails you and keeps every submission in an inbox.

  1. 1Create a form and copy its key

    Sign up with Google, create a form and enter the email address that should receive submissions. Copy the form key from the dashboard: it replaces YOUR_FORM_KEY below. The free plan includes 500 submissions a month.

  2. 2Add your form key

    With Vite, variables prefixed VITE_ are available in the browser.

    .env
    VITE_FORMCRATE_KEY=YOUR_FORM_KEY
  3. 3Create the component

    Sending Accept: application/json makes Formcrate answer with JSON instead of redirecting, so you can show your own success message without leaving the page.

    src/ContactForm.jsx
    import { useState } from 'react';
    
    const ENDPOINT = `https://www.formcrate.dev/api/submit/${import.meta.env.VITE_FORMCRATE_KEY}`;
    
    export default function ContactForm() {
      const [status, setStatus] = useState('idle');
    
      async function onSubmit(e) {
        e.preventDefault();
        setStatus('sending');
        const res = await fetch(ENDPOINT, {
          method: 'POST',
          headers: { Accept: 'application/json' },
          body: new FormData(e.currentTarget),
        });
        setStatus(res.ok ? 'sent' : 'error');
      }
    
      if (status === 'sent') return <p>Thanks! We'll be in touch.</p>;
    
      return (
        <form onSubmit={onSubmit}>
          <input type="text" name="name" placeholder="Name" required />
          <input type="email" name="email" placeholder="Email" required />
          <textarea name="message" placeholder="Message" required />
          <input type="text" name="_gotcha" style={{ display: 'none' }} tabIndex={-1} autoComplete="off" />
          <button type="submit" disabled={status === 'sending'}>
            {status === 'sending' ? 'Sending…' : 'Send'}
          </button>
          {status === 'error' && <p>Something went wrong. Please try again.</p>}
        </form>
      );
    }
  4. 4Send a test submission

    Fill in the form on your site and submit it. The message appears in your Formcrate inbox and arrives by email within a few seconds. Anything that looks like spam goes to the Spam tab instead and isn't emailed.

  5. 5Lock the form to your domain

    Your key is visible in the page source, which is normal for form backends. In the form settings, add your domain under Domain lock so other websites can't post to your form from the browser.

Tips

  • Create React App uses REACT_APP_ instead: process.env.REACT_APP_FORMCRATE_KEY.
  • Prefer sending JSON? Post JSON.stringify({...}) with Content-Type: application/json; Formcrate accepts both.

Get your React form working

Free for 500 submissions a month. Spam filtering, email alerts and an inbox included. No card required.

Create a free form

Guides for other stacks