Next.js
Add the RSVP widget to a Next.js App Router page, and create RSVPs from a server action.
The widget
npm install @whocoming/react"use client";
import { WhoComingRsvp } from "@whocoming/react";
export function Rsvp({ eventId }: { eventId: string }) {
return (
<WhoComingRsvp
event={eventId}
onRsvp={(detail) => console.log("RSVP", detail.rsvpId, detail.status)}
/>
);
}import { Rsvp } from "./rsvp";
export default function EventsPage() {
return (
<main>
<h1>Friday Night Magic</h1>
<Rsvp eventId="evt_demo0000000000000001" />
</main>
);
}The page itself stays a Server Component; only the small rsvp.tsx file runs in the browser.
Without the React package
The custom element works in JSX as is. Load the script with next/script and tell TypeScript about the tag once:
import Script from "next/script";
export default function EventsPage() {
return (
<>
<Script src="https://cdn.whocoming.com/embed.js" strategy="afterInteractive" />
<whocoming-rsvp event="evt_demo0000000000000001" />
</>
);
}import type { DetailedHTMLProps, HTMLAttributes } from "react";
declare module "react" {
namespace JSX {
interface IntrinsicElements {
"whocoming-rsvp": DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement> & {
event: string;
theme?: "auto" | "light" | "dark";
accent?: string;
compact?: boolean;
"hide-count"?: boolean;
strings?: string;
};
}
}
}Create RSVPs from your server
When the form is your own, call the API from a server action. The key stays on the server.
WHOCOMING_API_KEY=wc_test_..."use server";
export async function rsvp(formData: FormData) {
const res = await fetch(
"https://api.whocoming.com/v1/events/evt_demo0000000000000001/rsvps",
{
method: "POST",
headers: {
Authorization: `Bearer ${process.env.WHOCOMING_API_KEY}`,
"Content-Type": "application/json",
"Idempotency-Key": crypto.randomUUID(),
},
body: JSON.stringify({
name: formData.get("name"),
email: formData.get("email"),
}),
},
);
if (!res.ok) {
const problem = await res.json();
// problem.code is stable: "capacity_reached", "already_registered", ...
throw new Error(problem.detail);
}
return res.json();
}Or use @whocoming/sdk, which adds types, retries and pagination.
Never put a wc_live_ or wc_test_ key in a client component or a NEXT_PUBLIC_ variable. Anything with that prefix ships to every visitor.