CACHED_CALLS

tcmts.cli.test.e2e.prod.CACHED_CALLS · #bas3cnc2 · term · runs anywhere

Two server components on a page, each asking a cached function the same thing.

export const CACHED_CALLS = `// tcm: namespace counted
import { cache, cacheSignal } from "react";

export const calls = { n: 0 };

export const counted = cache(async (key: string) => {
  calls.n++;
  return \`\${key}\${calls.n}\`;
});

export async function A() {
  return <p className="a">{await counted("x")}</p>;
}

export async function B() {
  return <p className="b">{await counted("x")}:{String(cacheSignal() !== null)}</p>;
}

export function App() {
  return (
    <main>
      <A />
      <B />
    </main>
  );
}
`

used by