Dev Helpers
← Back

Session clash detector

Place this file at app/register/page.tsx in an App Router project.

Open this example in the interactive library

Source code

// app/register/page.tsx

export default async function SessionClashDetector({
  searchParams,
}: {
  searchParams: Promise<Record<string, string | string[] | undefined>>;
}) {
  const q = await searchParams;
  const list = [q.a, q.b];
  const time: Record<string, number> = { design: 10, print: 10, ink: 14 };
  const [a, b] = list.map((x) => (typeof x === "string" ? time[x] : undefined));
  return (
    <p>
      {a === undefined || b === undefined
        ? "Choose two sessions"
        : a === b
          ? "These sessions overlap"
          : "Both sessions fit"}
    </p>
  );
}