UNDER_A_BASE

tcmts.cli.test.e2e.prod.UNDER_A_BASE · #2t6a6qyk · term · runs anywhere

An app under a path of a site: links, its server and its cookies are under it, from the server's first paint on.

export const UNDER_A_BASE = `// tcm: namespace ui
import { setCookie } from "#codebase/lib/server";
import { href, match, useAppLinks, useLocation } from "#codebase/ui/lib/react";
import { useState } from "react";

export async function greet(name: string): Promise<string> {
  setCookie("seen", "yes", { httpOnly: false });
  return \`hello \${name}\`;
}

export function App() {
  useAppLinks();
  const at = useLocation();
  const [said, setSaid] = useState("");
  return (
    <main>
      <h1>{match("/about", at.path) ? "about" : "home"}</h1>
      <a id="about" href={href("/about")}>about</a>
      <button id="greet" onClick={async () => setSaid(await greet("you"))}>greet</button>
      <p id="said">{said}</p>
    </main>
  );
}
`

used by