{"id":50423685,"url":"https://github.com/aakashns/tanstack-router-theme-provider","last_synced_at":"2026-05-31T09:31:04.527Z","repository":{"id":350825412,"uuid":"1208400087","full_name":"aakashns/tanstack-router-theme-provider","owner":"aakashns","description":"SSR-friendly dark mode provider \u0026 useTheme hook for TanStack Router \u0026 TanStack Start","archived":false,"fork":false,"pushed_at":"2026-04-12T09:52:23.000Z","size":95,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-12T10:22:30.436Z","etag":null,"topics":["javascript","react","tanstack-router","tanstack-start"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/tanstack-router-theme-provider","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aakashns.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-04-12T08:15:43.000Z","updated_at":"2026-04-12T10:04:05.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/aakashns/tanstack-router-theme-provider","commit_stats":null,"previous_names":["aakashns/tanstack-router-theme-provider"],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/aakashns/tanstack-router-theme-provider","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aakashns%2Ftanstack-router-theme-provider","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aakashns%2Ftanstack-router-theme-provider/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aakashns%2Ftanstack-router-theme-provider/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aakashns%2Ftanstack-router-theme-provider/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aakashns","download_url":"https://codeload.github.com/aakashns/tanstack-router-theme-provider/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aakashns%2Ftanstack-router-theme-provider/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33726718,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-31T02:00:06.040Z","response_time":95,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","react","tanstack-router","tanstack-start"],"created_at":"2026-05-31T09:31:03.536Z","updated_at":"2026-05-31T09:31:04.522Z","avatar_url":"https://github.com/aakashns.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tanstack-router-theme-provider [![npm version](https://img.shields.io/npm/v/tanstack-router-theme-provider)](https://www.npmjs.com/package/tanstack-router-theme-provider)\n\nSSR-friendly `\u003cThemeProvider /\u003e` and `useTheme` hook for dark mode support in TanStack Router and TanStack Start apps.\n\n## Features\n\n- Perfect dark mode support in 2 lines of code\n- Supports `light`, `dark`, and `system` themes\n- Compatible with [shadcn-ui](https://ui.shadcn.com) out-of-the-box\n- Persists the selected theme in `localStorage`\n- Applies `dark` or `light` class to the root `\u003chtml\u003e`\n- Sets the browser `color-scheme` automatically\n- Syncs theme changes across browser tabs instantaneously\n- Includes startup script to prevent avoid theme flicker on first paint (FOUC)\n\n## Installation\n\n```bash\nnpm install tanstack-router-theme-provider\n```\n\nPeer dependencies:\n\n- `react` `\u003e=18.0.0`\n- `react-dom` `\u003e=18.0.0`\n- `@tanstack/react-router` `\u003e=1.0.0`\n\n## Usage\n\nWrap your root route (`src/routes/__root.tsx`) with `\u003cThemeProvider\u003e` and add `supressHydrationWarning` on the `\u003chtml\u003e` tag:\n\n```tsx\n// add this after existing imports..\nimport { ThemeProvider } from 'tanstack-router-theme-provider'\n\nfunction RootComponent() {\n  return (\n    \u003chtml lang=\"en\" suppressHydrationWarning\u003e\n      \u003chead\u003e\n        \u003cHeadContent /\u003e\n      \u003c/head\u003e\n      \u003cbody\u003e\n        \u003cThemeProvider\u003e \n          \u003cOutlet /\u003e\n          \u003cScripts /\u003e\n        \u003c/ThemeProvider\u003e\n      \u003c/body\u003e\n    \u003c/html\u003e\n  )\n}\n\nexport const Route = createRootRoute({\n    components: RootComponent,\n    // other code..\n})\n\n```\n\nUse `useTheme` anywhere below the provider.\n\n```tsx\nimport { useTheme } from 'tanstack-router-theme-provider'\n\nexport function ThemeToggle() {\n  const { theme, resolvedTheme, setTheme, mounted } = useTheme()\n\n  if (!mounted) return null\n\n  return (\n    \u003cbutton onClick={() =\u003e setTheme(theme === 'dark' ? 'light' : 'dark')}\u003e\n      Current theme: {theme} ({resolvedTheme})\n    \u003c/button\u003e\n  )\n}\n```\n\nHow it works:\n- `theme` can have the value `light`, `dark`, or `system` (i.e. OS setting)\n- `setTheme` stores the provided theme in `localStorage` on the client\n- `resolvedTheme` is `undefined` on the server (i.e. during SSR) since `localStorage` is not accessible there\n- `resolvedTheme` is `light` or `dark` on the client based on the `prefers-color-scheme: dark` media query\n- `mounted` is `false` on the server (i.e. during SSR) and `true` on the client\n\n## Reference\n\nYou can customize the `ThemeProvider` provider using the following props:\n\n| Name | Type | Description | Default |\n| --- | --- | --- | --- |\n| `children` | `React.ReactNode` | The app content rendered inside the provider. | Required |\n| `defaultTheme` | `'dark' \\| 'light' \\| 'system'` | The initial theme to use when there is no saved value in storage. | `'system'` |\n| `storageKey` | `string` | The `localStorage` key used to persist the selected theme. | `'tanstack-ui-theme'` |\n\n## Development\n\n- Install dependencies:\n\n```bash\nnpm install\n```\n\n- Build the library:\n\n```bash\nnpm run build\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faakashns%2Ftanstack-router-theme-provider","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faakashns%2Ftanstack-router-theme-provider","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faakashns%2Ftanstack-router-theme-provider/lists"}