MCPcopy Create free account
hub / github.com/code100x/daily-code / Print

Function Print

apps/web/components/Print.tsx:6–32  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4
5
6export function Print() {
7 const router = useRouter();
8
9 useEffect(() => {
10 // Open all <details> elements
11 document.querySelectorAll("details").forEach((e) => (e.open = true));
12
13
14 const closeWindow = () => {
15 console.log("PDF has been printed.");
16 window.close();
17 };
18
19 // Add event listener for 'afterprint' event
20 window.addEventListener("afterprint", closeWindow);
21
22 // Print the document
23 print();
24
25 // Clean up: Remove the event listener when component unmounts
26 return () => {
27 window.removeEventListener("afterprint", closeWindow);
28 };
29 }, [router]);
30
31 return null;
32}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected