Skip to content
Source
Sign inSign up
fuko/trytanstackdb.com
Open History to see the last commit

__root.tsx

68 lines2.1 KB

1import { HeadContent, Outlet, Scripts, createRootRouteWithContext } from "@tanstack/react-router";
2import { TanStackRouterDevtoolsPanel } from "@tanstack/react-router-devtools";
3import { TanStackDevtools } from "@tanstack/react-devtools";
4import type { QueryClient } from "@tanstack/react-query";
5import type { ReactNode } from "react";
6​
7import { AppNotifications } from "../components/shell/app-notifications";
8import TanStackQueryDevtools from "../integrations/tanstack-query/devtools";
9import { themeInitScript } from "../lib/theme";
10import appCss from "../styles.css?url";
11​
12interface MyRouterContext {
13 queryClient: QueryClient;
15​
16export const Route = createRootRouteWithContext<MyRouterContext>()({
17 head: () => ({
18 meta: [
19 { charSet: "utf-8" },
20 { name: "viewport", content: "width=device-width, initial-scale=1, viewport-fit=cover" },
21 { title: "Try TanStack DB — an interactive guide" },
22 {
23 name: "description",
24 content: "Learn TanStack DB by using a notes app next to the guide that explains it.",
25 },
26 ],
27 links: [{ rel: "stylesheet", href: appCss }],
28 }),
29 shellComponent: RootDocument,
30 component: RootLayout,
31});
32​
33/**
34 * Shared by every page. Rollback toasts and guide progress live here, not in
35 * the Notes app: a change can settle after the reader has moved on to a
36 * deep dive, and they should still hear about it.
37 */
38function RootLayout() {
39 return (
40 <>
41 <Outlet />
42 <AppNotifications />
43 </>
44 );
46​
47function RootDocument({ children }: { children: ReactNode }) {
48 return (
49 <html lang="en" suppressHydrationWarning>
50 <head>
51 {/* Sets the light/dark class before first paint. */}
52 <script dangerouslySetInnerHTML={{ __html: themeInitScript }} />
53 <HeadContent />
54 </head>
55 <body>
56 {children}
57 <TanStackDevtools
58 config={{ position: "bottom-right", hideUntilHover: true }}
59 plugins={[
60 { name: "Tanstack Router", render: <TanStackRouterDevtoolsPanel /> },
61 TanStackQueryDevtools,
62 ]}
63 />
64 <Scripts />
65 </body>
66 </html>
67 );