Skip to main content
On this page

React Router Setup

Set up Ninna UI in React Router framework mode with Tailwind CSS v4, server rendering, and matching client hydration.

Start with the CLI

Create a configured Ninna UI project, or follow the manual setup below for an existing application.

npx @ninna-ui/cli@latest init my-app --template react-router --preset ocean
cd my-app
npm run dev

Use Node.js 24 LTS. Omit --template for the framework prompt, or change --preset to select another theme. This command installs the published CLI; see the installation guide for release status, flags, and package-manager instructions.

Prerequisites

  • Node.js 24 LTS recommended
  • React Router framework mode (the CLI starter uses v8)
  • Tailwind CSS v4

Create Project

Skip this step if you already have a React Router project.

npx create-react-router@latest my-app
cd my-app

Install Ninna UI

Install the component packages you need. All packages auto-install @ninna-ui/core.

pnpm add @ninna-ui/primitives@latest @ninna-ui/feedback@latest @ninna-ui/forms@latest @ninna-ui/layout@latest

You can also install individual packages later - e.g. @ninna-ui/overlays, @ninna-ui/navigation, @ninna-ui/data-display.

Install Tailwind CSS

React Router uses Vite under the hood, so use the @tailwindcss/vite plugin.

pnpm add -D tailwindcss @tailwindcss/vite

Configure Vite

Add the Tailwind CSS plugin to your Vite config alongside the React Router plugin.

import { reactRouter } from "@react-router/dev/vite";
import { defineConfig } from "vite";
import tailwindcss from "@tailwindcss/vite";
export default defineConfig({
plugins: [reactRouter(), tailwindcss()],
});

CSS Setup

Replace the contents of your global CSS file.

In app/index.css (or equivalent global CSS):

@import "tailwindcss";
@import "@ninna-ui/core/theme/presets/default.css";
@variant dark (&:is(.dark *));

Then add data-theme to the <html> element in your root layout:

// app/root.tsx
import type { ReactNode } from "react";
import { Links, Meta, Outlet, Scripts, ScrollRestoration } from "react-router";
import "./index.css";
export function Layout({ children }: { children: ReactNode }) {
return (
<html lang="en" data-theme="default">
<head>
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<Meta />
<Links />
</head>
<body className="min-h-screen bg-base-50 text-base-content antialiased">
{children}
<ScrollRestoration />
<Scripts />
</body>
</html>
);
}
export default function App() {
return <Outlet />;
}

The theme preset automatically includes all utility classes used by Ninna UI components - no @source directive needed. Keep the server and first client render identical. The data-theme attribute is required — it must match the preset name from your CSS import for theme variables to activate. It also enables per-section theming by nesting different data-theme values.

Your First Component

Verify the setup by rendering a Ninna UI component.

import { Button, Heading, Text } from "@ninna-ui/primitives";
export default function Home() {
return (
<div className="p-8">
<Heading as="h1" size="3xl">Hello Ninna UI</Heading>
<Text className="text-base-content/70 mt-2">It works!</Text>
<Button color="primary" className="mt-4">Click me</Button>
</div>
);
}

This site (ninna-ui.dev) is itself built with React Router v7 + Ninna UI!

SSR Notes

Framework mode supports server rendering, client rendering, and pre-rendering.

Framework mode enables server rendering by default. Keep ssr: true for request-time rendering, or set ssr: false in react-router.config.ts for SPA mode. Ninna UI works in both modes.

Preserve Scripts in the root layout so the browser can hydrate the page. Use the same initial state on the server and client, and read browser APIs in effects or event handlers. Do not hide mismatches with a blanket hydration-warning suppression.

// react-router.config.ts
import type { Config } from "@react-router/dev/config";
export default {
ssr: true, // Enable SSR - Ninna UI works with both modes
} satisfies Config;

Theme Presets

Switch themes by changing the CSS import and the data-theme attribute.

/* 1. Change the CSS import in index.css */
/* Default - Electric purple + magenta */
@import "@ninna-ui/core/theme/presets/default.css";
/* Ocean - Blue + cyan */
@import "@ninna-ui/core/theme/presets/ocean.css";
/* Sunset - Orange + rose */
@import "@ninna-ui/core/theme/presets/sunset.css";
/* Forest - Green + amber */
@import "@ninna-ui/core/theme/presets/forest.css";
/* Minimal - Monochrome */
@import "@ninna-ui/core/theme/presets/minimal.css";
/* 2. Update data-theme in app/root.tsx */
/* <html lang="en" data-theme="ocean"> */

Dark mode works automatically via prefers-color-scheme or by adding the .dark class to <html>. The data-theme attribute is required for theme variables to activate.