# React and Next.js

Use PaceForms from any React application — no SDK needed, just fetch.

## React component

```jsx
import { useState } from 'react';

const ENDPOINT = 'https://app.paceforms.com/api/f/NR-6Ww88ET';

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

  async function handleSubmit(e) {
    e.preventDefault();
    setStatus('loading');
    const res = await fetch(ENDPOINT, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify(
        Object.fromEntries(new FormData(e.target))
      ),
    });
    setStatus(res.ok ? 'success' : 'error');
  }

  if (status === 'success') return <p>Thanks! We'll be in touch.</p>;

  return (
    <form onSubmit={handleSubmit}>
      <input name="name" placeholder="Name" required />
      <input name="email" type="email" placeholder="Email" required />
      <textarea name="message" placeholder="Message" />
      <button type="submit" disabled={status === 'loading'}>
        {status === 'loading' ? 'Sending...' : 'Send Message'}
      </button>
      {status === 'error' && <p>Something went wrong.</p>}
    </form>
  );
}
```

## Next.js Server Action (App Router)

```js
'use server';

export async function submitForm(formData) {
  const res = await fetch(
    'https://app.paceforms.com/api/f/NR-6Ww88ET',
    {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({
        name: formData.get('name'),
        email: formData.get('email'),
        message: formData.get('message'),
      }),
    }
  );
  if (!res.ok) throw new Error('Submission failed');
  return await res.json();
}
```
