--- title: TanStack Start description: "A guide for installing and using Yamada UI with TanStack Start projects." --- # TanStack Start A guide for installing and using Yamada UI with TanStack Start projects. ## Installation ### Create application Create TanStack Start application. ```bash pnpm create @tanstack/start my-app ``` ```bash npx create @tanstack/start my-app ``` ```bash yarn create @tanstack/start my-app ``` ```bash bun create @tanstack/start my-app ``` ### Setup Running the command will create the necessary files and folders in your project. ```bash pnpm dlx @yamada-ui/cli init ``` ```bash npx @yamada-ui/cli init ``` ```bash yarn dlx @yamada-ui/cli init ``` ```bash bunx @yamada-ui/cli init ``` ### Install the package Install `@workspaces/ui` to your application. ```bash pnpm add "@workspaces/ui@workspace:*" ``` ```bash npm install "@workspaces/ui@workspace:*" ``` ```bash yarn add "@workspaces/ui@workspace:*" ``` ```bash bun add "@workspaces/ui@workspace:*" ``` ### Add provider After installing, add `UIProvider` to the root of your application. To suppress hydration errors, add `suppressHydrationWarning` to the `html` and `body` tags. ```tsx import { HeadContent, Scripts, createRootRoute } from "@tanstack/react-router" import { TanStackRouterDevtoolsPanel } from "@tanstack/react-router-devtools" import { TanStackDevtools } from "@tanstack/react-devtools" import { UIProvider } from "@workspaces/ui" export const Route = createRootRoute({ head: () => ({ meta: [ { charSet: "utf-8" }, { name: "viewport", content: "width=device-width, initial-scale=1" }, { title: "TanStack Start Starter" }, ], }), shellComponent: RootDocument, }) function RootDocument({ children }: { children: React.ReactNode }) { return ( {children} , }, ]} /> ) } ``` ### Use components After adding `UIProvider`, you can use the components in your application. ```tsx import { createFileRoute } from "@tanstack/react-router" import { Button } from "@workspaces/ui" export const Route = createFileRoute("/")({ component: App }) function App() { return } ``` That's it! You've successfully set up Yamada UI. ## Scripts ### ColorModeScript To use [Color Mode](https://yamada-ui.com/docs/theming/color-mode.md), you need to add `ColorModeScript` to the `body` to ensure it works correctly. This is because color mode is implemented using `localStorage` or `cookies`, and adding the script ensures proper synchronization when the page loads. ```tsx import { HeadContent, Scripts, createRootRoute } from "@tanstack/react-router" import { TanStackRouterDevtoolsPanel } from "@tanstack/react-router-devtools" import { TanStackDevtools } from "@tanstack/react-devtools" import { ColorModeScript, UIProvider } from "@workspaces/ui" import { createServerFn } from "@tanstack/react-start" import { getRequestHeader } from "@tanstack/react-start/server" const getCookie = createServerFn({ method: "GET" }).handler(async () => { return getRequestHeader("cookie") ?? "" }) export const Route = createRootRoute({ loader: async () => ({ cookie: await getCookie(), }), head: () => ({ meta: [ { charSet: "utf-8" }, { name: "viewport", content: "width=device-width, initial-scale=1" }, { title: "TanStack Start Starter" }, ], }), shellComponent: RootDocument, }) function RootDocument({ children }: { children: React.ReactNode }) { const { cookie } = Route.useLoaderData() return ( {children} , }, ]} /> ) } ``` If you change the `defaultColorMode` in your [config](https://yamada-ui.com/docs/theming/configuration/overview.md), set the `defaultValue` prop on `ColorModeScript`. ```tsx import { HeadContent, Scripts, createRootRoute } from "@tanstack/react-router" import { TanStackRouterDevtoolsPanel } from "@tanstack/react-router-devtools" import { TanStackDevtools } from "@tanstack/react-devtools" import { ColorModeScript, UIProvider } from "@workspaces/ui" import { createServerFn } from "@tanstack/react-start" import { getRequestHeader } from "@tanstack/react-start/server" import { config } from "@workspaces/theme" const getCookie = createServerFn({ method: "GET" }).handler(async () => { return getRequestHeader("cookie") ?? "" }) export const Route = createRootRoute({ loader: async () => ({ cookie: await getCookie(), }), head: () => ({ meta: [ { charSet: "utf-8" }, { name: "viewport", content: "width=device-width, initial-scale=1" }, { title: "TanStack Start Starter" }, ], }), shellComponent: RootDocument, }) function RootDocument({ children }: { children: React.ReactNode }) { const { cookie } = Route.useLoaderData() return ( {children} , }, ]} /> ) } ``` ### ThemeSchemeScript To use [theme switching](https://yamada-ui.com/docs/theming/switching-themes.md), you need to add `ThemeSchemeScript` to the `body` to ensure it works correctly. This is because theme switching is implemented using `localStorage` or `cookies`, and adding the script ensures proper synchronization when the page loads. ```tsx import { HeadContent, Scripts, createRootRoute } from "@tanstack/react-router" import { TanStackRouterDevtoolsPanel } from "@tanstack/react-router-devtools" import { TanStackDevtools } from "@tanstack/react-devtools" import { ThemeSchemeScript, UIProvider } from "@workspaces/ui" import { createServerFn } from "@tanstack/react-start" import { getRequestHeader } from "@tanstack/react-start/server" const getCookie = createServerFn({ method: "GET" }).handler(async () => { return getRequestHeader("cookie") ?? "" }) export const Route = createRootRoute({ loader: async () => ({ cookie: await getCookie(), }), head: () => ({ meta: [ { charSet: "utf-8" }, { name: "viewport", content: "width=device-width, initial-scale=1" }, { title: "TanStack Start Starter" }, ], }), shellComponent: RootDocument, }) function RootDocument({ children }: { children: React.ReactNode }) { const { cookie } = Route.useLoaderData() return ( {children} , }, ]} /> ) } ``` If you change the `defaultThemeScheme` in your [config](https://yamada-ui.com/docs/theming/configuration/overview.md), set the `defaultValue` prop on `ThemeSchemeScript`. ```tsx import { HeadContent, Scripts, createRootRoute } from "@tanstack/react-router" import { TanStackRouterDevtoolsPanel } from "@tanstack/react-router-devtools" import { TanStackDevtools } from "@tanstack/react-devtools" import { ThemeSchemeScript, UIProvider } from "@workspaces/ui" import { createServerFn } from "@tanstack/react-start" import { getRequestHeader } from "@tanstack/react-start/server" import { config } from "@workspaces/theme" const getCookie = createServerFn({ method: "GET" }).handler(async () => { return getRequestHeader("cookie") ?? "" }) export const Route = createRootRoute({ loader: async () => ({ cookie: await getCookie(), }), head: () => ({ meta: [ { charSet: "utf-8" }, { name: "viewport", content: "width=device-width, initial-scale=1" }, { title: "TanStack Start Starter" }, ], }), shellComponent: RootDocument, }) function RootDocument({ children }: { children: React.ReactNode }) { const { cookie } = Route.useLoaderData() return ( {children} , }, ]} /> ) } ``` ## Component Integration You can integrate TanStack Start components such as [Link](https://tanstack.com/router/latest/docs/guide/navigation#link-component) with Yamada UI components. ### Link ```tsx import type { LinkComponent } from "@tanstack/react-router" import { createLink } from "@tanstack/react-router" import { Button, IconButton, Link } from "@workspaces/ui" const CreatedLink = createLink(Link) export const RouterLink: LinkComponent = (props) => { return } const CreatedLinkButton = createLink(Button) export const RouterLinkButton: LinkComponent = ( props, ) => { return } const CreatedLinkIconButton = createLink(IconButton) export const RouterLinkIconButton: LinkComponent< typeof CreatedLinkIconButton > = (props) => { return } ```