Skip to content
Lazyform
Docs menu

Developers

SDK and React hook

The lazyform npm package sends forms from any JavaScript app, with a useLazyform hook for React.

The lazyform package is a small client for the submit endpoint. It handles JSON and files, adds the time-trap field for better spam protection, and gives you typed results. React apps get a useLazyform() hook with loading, success and error states.

The package is being finished. The examples below show the intended API; until it's published, use fetch, which does the same with a few more lines.

Install

bash
npm install lazyform

React

tsx
import { useLazyform } from 'lazyform/react'

export function ContactForm() {
  const { submit, status, error } = useLazyform({ accessKey: 'YOUR_ACCESS_KEY' })

  if (status === 'success') return <p>Thanks! We'll be in touch.</p>
  return (
    <form onSubmit={submit}>
      <input name="email" type="email" required />
      <textarea name="message" required />
      <button disabled={status === 'submitting'}>Send</button>
      {error && <p role="alert">{error.message}</p>}
    </form>
  )
}

Any JavaScript

js
import { createClient } from 'lazyform'

const lazyform = createClient({ accessKey: 'YOUR_ACCESS_KEY' })
const result = await lazyform.submit({ email: 'ada@example.com', message: 'Hello!' })

Results have the same shape as the endpoint's JSON. See responses and errors.