Skip to content
Lazyform

Contact form for React

A copy-paste React contact form that sends submissions by email, Telegram or Slack. Works in Vite or any other React setup, with no backend to write.

Free plan: 250 submissions a month, forever.

Why a form backend for React

A React app built with Vite or a similar tool is a bundle of static files once it's built. There's no server to receive a form, so you either set up an API somewhere or send the data to a service that handles it.

Lazyform is that service. Your component posts the form, gets back a small JSON answer, and shows a success or error message. Spam checks, storage and delivery happen on our side.

A working contact form

Replace YOUR_ACCESS_KEY with your key from /login.

src/ContactForm.jsx
import { useState } from 'react'

export default function ContactForm() {
  const [status, setStatus] = useState('idle')
  const [error, setError] = useState('')

  async function handleSubmit(event) {
    event.preventDefault()
    setStatus('sending')
    const form = event.currentTarget

    const res = await fetch('https://lazyform-api.xvelopers.com/submit', {
      method: 'POST',
      headers: { Accept: 'application/json' },
      body: new FormData(form),
    })
    const data = await res.json()

    if (data.success) {
      setStatus('sent')
      form.reset()
    } else {
      setStatus('error')
      setError(data.error.message)
    }
  }

  if (status === 'sent') return <p>Thanks! We'll get back to you soon.</p>

  return (
    <form onSubmit={handleSubmit}>
      <input type="hidden" name="access_key" value="YOUR_ACCESS_KEY" />
      <input type="text" name="name" placeholder="Your name" required />
      <input type="email" name="email" placeholder="you@example.com" required />
      <textarea name="message" placeholder="Your message" required />
      <input type="checkbox" name="botcheck" className="hidden" style={{ display: 'none' }} />
      <button type="submit" disabled={status === 'sending'}>
        {status === 'sending' ? 'Sending…' : 'Send'}
      </button>
      {status === 'error' && <p role="alert">{error}</p>}
    </form>
  )
}

Using FormData means you don't need a state variable for every input. Add a field to the JSX and it's sent automatically.

Get submissions where you want them

Submissions go to your email first. Turn on Telegram, Slack, Discord or WhatsApp alerts, or copy each one into Google Sheets, Notion or Airtable. See all integrations.

Full guide

The React guide shows a JSON version, file uploads, captcha and how to handle each error code.

Questions

Does this work with Vite and other React setups?

Yes. The component only uses useState and fetch, so it runs anywhere React runs: Vite, Parcel, an older Create React App project, or a React island inside another framework.

Why do I get JSON back instead of a redirect?

The component sends an Accept: application/json header, so Lazyform answers with JSON and your component decides what to show. Without that header the browser would be redirected.

Can I use a form library like React Hook Form?

Yes. In your submit handler, send the values as FormData or JSON to the same endpoint, with access_key included and botcheck left empty.

Where should I keep the access key?

In the component or in an environment variable such as VITE_LAZYFORM_KEY. The key is public by design: it can send submissions, not read them.