Contents: React
React
Works with any React setup, such as Vite. The component posts with fetch and shows the result without leaving the page.
import { useState } from 'react';
export default function ContactForm() {
const [status, setStatus] = useState('idle');
async function handleSubmit(event) {
event.preventDefault();
setStatus('sending');
const data = new FormData(event.currentTarget);
data.append('access_key', import.meta.env.VITE_FORMIZ_KEY);
const res = await fetch('https://api.formiz.app/submit', {
method: 'POST',
body: data,
});
setStatus(res.ok ? 'sent' : 'error');
}
return (
<form onSubmit={handleSubmit}>
<input name="name" required />
<input name="email" type="email" required />
<textarea name="message" required />
<button disabled={status === 'sending'}>Send</button>
{status === 'sent' && <p>Thanks! Your message is on its way.</p>}
</form>
);
}Environment variable
With Vite, put the key in .env as VITE_FORMIZ_KEY. Other build tools use their own prefix; the key only needs to be available in the browser.
VITE_FORMIZ_KEY=fmz_your_key_here