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

__root.tsx

52 lines1.7 KB

1import { HeadContent, 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 TanStackQueryDevtools from "../integrations/tanstack-query/devtools";
8import { themeInitScript } from "../lib/theme";
9import appCss from "../styles.css?url";
10​
11interface MyRouterContext {
12 queryClient: QueryClient;
14​
15export const Route = createRootRouteWithContext<MyRouterContext>()({
16 head: () => ({
17 meta: [
18 { charSet: "utf-8" },
19 { name: "viewport", content: "width=device-width, initial-scale=1, viewport-fit=cover" },
20 { title: "Try TanStack DB — an interactive guide" },
21 {
22 name: "description",
23 content: "Learn TanStack DB by using a notes app next to the guide that explains it.",
24 },
25 ],
26 links: [{ rel: "stylesheet", href: appCss }],
27 }),
28 shellComponent: RootDocument,
29});
30​
31function RootDocument({ children }: { children: ReactNode }) {
32 return (
33 <html lang="en" suppressHydrationWarning>
34 <head>
35 {/* Sets the light/dark class before first paint. */}
36 <script dangerouslySetInnerHTML={{ __html: themeInitScript }} />
37 <HeadContent />
38 </head>
39 <body>
40 {children}
41 <TanStackDevtools
42 config={{ position: "bottom-right", hideUntilHover: true }}
43 plugins={[
44 { name: "Tanstack Router", render: <TanStackRouterDevtoolsPanel /> },
45 TanStackQueryDevtools,
46 ]}
47 />
48 <Scripts />
49 </body>
50 </html>
51 );