React + Vite
A single-page app collects signups in the browser. The gate and activation calls need your secret key, so they belong in your backend (see Node / any backend) or your auth provider’s server hooks (see Auth recipes).
.env
VITE_WAITLISTLY_PUBLIC_KEY=pk_your_public_keysrc/WaitlistForm.tsx
import { useState } from 'react';
export function WaitlistForm() {
const [message, setMessage] = useState('');
async function onSubmit(e: React.FormEvent<HTMLFormElement>) {
e.preventDefault();
const email = new FormData(e.currentTarget).get('email');
const res = await fetch('https://waitlistly.live/api/v1/contacts', {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'X-Waitlistly-Key': import.meta.env.VITE_WAITLISTLY_PUBLIC_KEY },
body: JSON.stringify({ email, ref: new URLSearchParams(location.search).get('ref') }),
});
const data = await res.json();
if (!res.ok) return setMessage(data.error);
setMessage(data.status === 'joined' ? `You're #${data.position}. Share ${data.referral_link}` : 'Check your inbox.');
}
return (
<form onSubmit={onSubmit}>
<input name="email" type="email" required />
<button>Join</button>
<p>{message}</p>
</form>
);
}Prefer not to write the fetch? Load the SDK and call Waitlistly.join({ email }). It also captures ?ref= and UTM tags.
Last updated on