<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ Ajay Patel - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ Ajay Patel - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Tue, 10 Nov 2026 21:32:18 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/author/ajaypatel9016/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How to Use shadcn/ui in React Native Applications [Full Handbook] ]]>
                </title>
                <description>
                    <![CDATA[ If you've built a couple of React Native apps, the following probably feels familiar. You start with a colors.ts file and a simple Button component. Everything looks fine at first. Then the design cha ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-use-shadcn-ui-in-react-native-applications-full-handbook/</link>
                <guid isPermaLink="false">6aecb9efa7a2ab6fb8e3fe94</guid>
                
                    <category>
                        <![CDATA[ shadcn ]]>
                    </category>
                
                    <category>
                        <![CDATA[ shadcn ui ]]>
                    </category>
                
                    <category>
                        <![CDATA[ React Native ]]>
                    </category>
                
                    <category>
                        <![CDATA[ handbook ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Ajay Patel ]]>
                </dc:creator>
                <pubDate>Thu, 05 Nov 2026 17:16:30 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/uploads/covers/5e1e335a7a1d3fcc59028c64/ddea2027-27b4-407e-83a5-d84bfd295627.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>If you've built a couple of React Native apps, the following probably feels familiar. You start with a <code>colors.ts</code> file and a simple <code>Button</code> component. Everything looks fine at first. Then the design changes a few times, and that small color file starts growing. Your Button also picks up another prop every time someone asks for a slightly different style.</p>
<p>The setup works at first, but after a few design changes, even a small update can mean checking several files across the project.</p>
<p>Here's what a typical color file looks like after a while:</p>
<pre><code class="language-tsx">export const colors = {
  primary: '#6e4836',
  primaryPressed: '#5a3a2b',
  textPrimary: '#261d16',
  textSecondary: '#72665e',
  // and forty more
};
</code></pre>
<p>And here's what a typical <code>Button</code> looks like after a few redesigns:</p>
<pre><code class="language-tsx">&lt;Button
  variant="primary"
  size="md"
  fullWidth
  loading={busy}
  containerStyle={styles.checkoutButton}
  labelStyle={styles.checkoutLabel}
/&gt;
</code></pre>
<p>These are simplified examples, but you get the idea. The color object keeps growing, and the Button collects more props to handle every new design request.</p>
<p>Each change seems reasonable when you make it. But the annoying part comes later, when changing one design decision means checking several files to see that nothing else has changed unexpectedly.</p>
<p>Part of the problem is how many component libraries are distributed. Their code lives in <code>node_modules</code>, so you usually customize them through the props and options they expose. When the library doesn't cover your exact use case, you add another prop or override. Keep doing that and the component can become harder to maintain than the original problem you were trying to solve.</p>
<p>This is one reason I like shadcn/ui's approach. You don't install a traditional component package and treat its components as fixed. The CLI copies the source code into your project, where you can change it whenever you need to. For React Native, there's a project built around the same idea called <a href="https://reactnativereusables.com/">React Native Reusables</a>.</p>
<p>To make this practical, I'll use React Native Reusables, Expo, and Uniwind to build a <strong>cart and checkout screen for a coffee shop's pickup orders</strong>. It includes order items with quantity controls, a pickup-time dropdown, a name field, an "own cup" toggle, a bill summary, a checkout bar that stays at the bottom, and an order-confirmation dialog. If you want to see how reusable sections come together in complete interfaces, you can also browse <a href="https://shadcnstudio.com/templates">shadcn templates</a>.</p>
<p>I'll also point out a few things that are easy to miss when working with these components, including:</p>
<ul>
<li>How shadcn/ui and its CLI work, and why you own the component code</li>
<li>How design tokens (named colors) replace a <code>colors.ts</code> file</li>
<li>How to use components such as Card, Select, Switch, and AlertDialog in React Native</li>
<li>How to handle mobile-specific issues, such as safe areas, keyboards, and tap targets</li>
<li>How to switch between light and dark mode, and how to change the whole theme from one file</li>
</ul>
<h2 id="heading-table-of-contents">Table of Contents</h2>
<ul>
<li><a href="#heading-prerequisites">Prerequisites</a></li>
<li><a href="#heading-tools-you-will-use">Tools You Will Use</a></li>
<li><a href="#heading-how-shadcnui-works">How shadcn/ui Works</a></li>
<li><a href="#heading-what-react-native-reusables-gives-you">What React Native Reusables Gives You</a></li>
<li><a href="#heading-what-youre-building">What You're Building</a></li>
<li><a href="#heading-step-1-create-the-app">Step 1: Create the App</a><ul>
<li><a href="#heading-answer-the-clis-questions">Answer the CLI's Questions</a></li>
<li><a href="#heading-look-at-the-project-structure">Look at the Project Structure</a></li>
<li><a href="#heading-run-the-app">Run the App</a></li>
</ul>
</li>
<li><a href="#heading-step-2-understand-the-theme-file">Step 2: Understand the Theme File</a><ul>
<li><a href="#heading-the-palette-also-exists-in-libthemets">The Palette Also Exists inlib/theme.ts</a></li>
<li><a href="#heading-try-it-change-one-color">Try It: Change One Color</a></li>
</ul>
</li>
<li><a href="#heading-step-3-read-three-core-components">Step 3: Read Three Core Components</a><ul>
<li><a href="#heading-the-text-component">The Text Component</a></li>
<li><a href="#heading-the-button-component">The Button Component</a></li>
<li><a href="#heading-the-icon-component">The Icon Component</a></li>
</ul>
</li>
<li><a href="#heading-step-4-add-the-components-you-need">Step 4: Add the Components You Need</a></li>
<li><a href="#heading-step-5-set-up-the-data-and-the-screen">Step 5: Set Up the Data and the Screen</a><ul>
<li><a href="#heading-the-screen-layout">The Screen Layout</a></li>
</ul>
</li>
<li><a href="#heading-step-6-build-the-order-rows">Step 6: Build the Order Rows</a></li>
<li><a href="#heading-step-7-build-the-pickup-options">Step 7: Build the Pickup Options</a><ul>
<li><a href="#heading-problem-1-portals-and-the-portalhost">Problem 1: Portals and the PortalHost</a></li>
<li><a href="#heading-problem-2-safe-area-insets">Problem 2: Safe Area Insets</a></li>
<li><a href="#heading-problem-3-the-select-value-is-an-object">Problem 3: The Select Value Is an Object</a></li>
<li><a href="#heading-making-the-label-tappable">Making the Label Tappable</a></li>
<li><a href="#heading-keyboard-props-for-the-name-field">Keyboard Props for the Name Field</a></li>
</ul>
</li>
<li><a href="#heading-step-8-build-the-bill-component">Step 8: Build the Bill Component</a></li>
<li><a href="#heading-step-9-build-the-fixed-checkout-bar">Step 9: Build the Fixed Checkout Bar</a><ul>
<li><a href="#heading-handling-the-home-indicator">Handling the Home Indicator</a></li>
<li><a href="#heading-a-note-on-thin-borders">A Note on Thin Borders</a></li>
</ul>
</li>
<li><a href="#heading-step-10-add-the-confirmation-and-put-the-screen-together">Step 10: Add the Confirmation and Put the Screen Together</a><ul>
<li><a href="#heading-1-it-also-needs-the-portalhost">1. It Also Needs thePortalHost</a></li>
<li><a href="#heading-2-the-footer-reverses-its-order-on-phones">2. The Footer Reverses its Order on Phones</a></li>
<li><a href="#heading-haptics">Haptics</a></li>
<li><a href="#heading-the-full-screen">The Full Screen</a></li>
</ul>
</li>
<li><a href="#heading-step-11-add-dark-mode">Step 11: Add Dark Mode</a><ul>
<li><a href="#heading-1-the-navigation-header">1. The Navigation Header</a></li>
<li><a href="#heading-2-the-status-bar">2. The Status Bar</a></li>
<li><a href="#heading-3-saving-the-choice">3. Saving the Choice</a></li>
</ul>
</li>
<li><a href="#heading-step-12-create-your-own-theme">Step 12: Create Your Own Theme</a><ul>
<li><a href="#heading-update-the-tokens">Update the Tokens</a></li>
<li><a href="#heading-update-libthemets">Update lib/theme.ts</a></li>
</ul>
</li>
<li><a href="#heading-common-mistakes-and-how-to-fix-them">Common Mistakes and How to Fix Them</a></li>
<li><a href="#heading-conclusion">Conclusion</a><ul>
<li><a href="#heading-resources">Resources</a></li>
</ul>
</li>
</ul>
<h2 id="heading-prerequisites">Prerequisites</h2>
<p>To follow along, you should have:</p>
<ul>
<li><strong>Node.js 20 or newer.</strong> You can use pnpm, npm, yarn, or bun. The commands in this tutorial use pnpm, so swap the prefix if you use something else.</li>
<li><strong>Basic knowledge of React and TypeScript</strong>, especially hooks such as <code>useState</code>.</li>
<li><strong>Some familiarity with React Native</strong>, such as <code>View</code>, <code>Text</code>, and <code>ScrollView</code>. You don't need to know Tailwind, but it helps.</li>
<li><strong>Optional:</strong> Xcode or Android Studio if you want to run the app in a simulator. Everything also runs in a web browser through React Native Web, and that's how the screenshots in this tutorial were taken.</li>
</ul>
<p>You don't need any accounts or API keys, and nothing here costs money.</p>
<h2 id="heading-tools-you-will-use">Tools You Will Use</h2>
<p>Before creating the app, let's look at the tools in this project. Each one has a specific job, and knowing that will make the setup easier to follow.</p>
<p><strong>shadcn/ui</strong> is a collection of UI components for the web. It's not installed as a package. Instead, a command-line tool (CLI) copies the source code of each component into your project, and from then on the code is yours to edit.</p>
<p><strong>React Native Reusables</strong> is the React Native version of shadcn/ui. It gives you components such as Button, Card, Select, and Dialog that are written for React Native and styled with Tailwind-style class names. It uses the same CLI idea as shadcn/ui.</p>
<p><strong>RN Primitives</strong> is a React Native port of Radix UI, which is the library that shadcn/ui uses for behavior on the web. A "primitive" is a component that handles the behavior but has no styling. For example, the <code>select</code> primitive knows how a dropdown opens and closes and how it's announced to screen readers, but it has no colors or borders. React Native Reusables adds the looks on top.</p>
<p><strong>Uniwind</strong> is a tool that lets you style React Native components with Tailwind CSS class names, such as <code>className="bg-primary p-4"</code>. It converts those classes into regular React Native styles while the app is being bundled, so there's no extra work at runtime. <a href="https://www.nativewind.dev/">Nativewind</a> does a similar job, and React Native Reusables supports both. This tutorial uses Uniwind.</p>
<p><strong>Expo and Expo Router</strong> provide the project setup, the development server, and file-based navigation. If you have used Next.js, Expo Router works in a similar way.</p>
<h2 id="heading-how-shadcnui-works">How shadcn/ui Works</h2>
<p>The React Native Reusables documentation opens with a quote from shadcn:</p>
<blockquote>
<p>This is not a component library. It is how you build your component library.</p>
</blockquote>
<p>You won't add shadcn/ui as a regular dependency in <code>package.json</code>. It uses a <strong>registry</strong> instead. A registry is a collection of JSON files hosted on a server. Each file describes a component and includes the information the CLI needs to add it to your project. When you run the CLI, it reads the relevant file and copies the component's source code into your project.</p>
<p>To see what this looks like, here's the registry entry for the <strong>Badge</strong> component. A Badge is a small label, such as the "Medium" tag next to a coffee in the cart you will build later. This is a shortened version of the real file:</p>
<pre><code class="language-json">{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "badge",
  "type": "registry:ui",
  "title": "Badge",
  "author": "@mrzachnugent",
  "description": "Displays a badge or a component that looks like a badge.",
  "dependencies": ["@rn-primitives/slot"],
  "registryDependencies": ["https://reactnativereusables.com/r/uniwind/text.json"],
  "files": [
    {
      "path": "./node_modules/@rnr/registry/src/uniwind/components/ui/badge.tsx",
      "content": "import { TextClassContext } from '@/components/ui/text';\nimport ...",
      "type": "registry:ui"
    }
  ]
}
</code></pre>
<p>The file is public, so you can look at it yourself:</p>
<pre><code class="language-bash">curl https://reactnativereusables.com/r/uniwind/badge.json
</code></pre>
<p>Here's what the important fields mean:</p>
<ul>
<li><code>content</code> holds the full source code of the component, stored as a string.</li>
<li><code>dependencies</code> lists npm packages that the component needs. The CLI installs these first.</li>
<li><code>registryDependencies</code> lists other registry entries that the component needs. In this case, Badge needs the <strong>Text</strong> component, which is a small wrapper around React Native's <code>Text</code> that you will read about in Step 3. When you run the CLI to add Badge, it also adds Text for you because of this field.</li>
</ul>
<p>That's how a component gets from the registry into your app. The registry stores the component information, and the CLI uses it to create the files in your repository. React Native Reusables uses the shadcn CLI behind the scenes, so you can follow the same workflow when adding React Native components.</p>
<p>There are a few reasons this approach is useful when you're building an app:</p>
<ol>
<li><strong>You own the file:</strong> A component such as <code>components/ui/button.tsx</code> sits in your repository and shows up in your Git diffs. If you want a darker pressed state, you edit that line. You don't need to invent a new prop, maintain a fork, or open an issue.</li>
<li><strong>Design lives in named colors instead of props:</strong> Colors are declared once as named roles, such as <code>primary</code>, <code>muted</code>, <code>border</code>, and <code>destructive</code>. You then use them in class names, like <code>className="bg-primary"</code>. This replaces the <code>colors.ts</code> file from the introduction, because there's one place that defines your colors, and every component reads from it. You'll set this up in Step 2.</li>
<li><strong>Behavior comes from a separate package:</strong> Things such as focus handling, open and close state, and screen reader support live in RN Primitives. You only write the styling.</li>
</ol>
<p>There's one trade-off to keep in mind. Since the component code is copied into your project, updates from the registry aren't applied automatically. If a bug is fixed upstream, you'll need to run the CLI again with <code>--overwrite</code>. If you have customized that component, you may also need to reapply your changes. This is worth considering before you make large changes to several components.</p>
<h2 id="heading-what-react-native-reusables-gives-you">What React Native Reusables Gives You</h2>
<p>At the time of writing, React Native Reusables includes thirty components: accordion, alert, alert-dialog, aspect-ratio, avatar, badge, button, card, checkbox, collapsible, context-menu, dialog, dropdown-menu, hover-card, input, label, menubar, popover, progress, radio-group, select, separator, skeleton, switch, tabs, text, textarea, toggle, toggle-group, and tooltip. The available components cover many of the building blocks you need for a typical app interface.</p>
<p>React Native is different from the web in several ways, so the components can't be an exact copy of the web version. The documentation lists the main differences, and you'll run into each of them in this tutorial. If you're also building web interfaces with shadcn/ui, <a href="https://shadcnstudio.com/components">shadcn components</a> can be useful when you need more ready-made examples to work from.</p>
<table>
<thead>
<tr>
<th>The difference</th>
<th>What it means</th>
<th>Where you will see it</th>
</tr>
</thead>
<tbody><tr>
<td>Portals need a <code>PortalHost</code></td>
<td>On the web, floating content such as dropdowns renders into <code>document.body</code>. React Native has no <code>document.body</code>, so you need a <code>PortalHost</code> component to render into.</td>
<td>Step 7</td>
</tr>
<tr>
<td>Styles don't cascade</td>
<td>A text color set on a parent view doesn't reach the text inside it, so React Native Reusables uses a <code>Text</code> component with a workaround.</td>
<td>Step 3</td>
</tr>
<tr>
<td>There are no <code>data-*</code> attributes</td>
<td>Web shadcn changes styles based on attributes like <code>data-state</code>. React Native has none, so variants depend on props and state.</td>
<td>Step 7</td>
</tr>
<tr>
<td>Icons take props instead of classes</td>
<td>Icon libraries expect <code>color</code> and <code>size</code> props, so icons are wrapped to accept class names.</td>
<td>Step 3</td>
</tr>
</tbody></table>
<h2 id="heading-what-youre-building">What You're Building</h2>
<p>We'll build a cart and checkout screen for a coffee shop where customers place an order and pick it up at the counter. The screen uses twelve components from the registry. While putting it together, I'll also explain a few React Native details that are easy to miss, including how dropdowns are rendered, how safe areas affect the layout, and how to keep the checkout bar visible while the rest of the page scrolls:</p>
<table>
<thead>
<tr>
<th>Part of the screen</th>
<th>Components used</th>
<th>The mobile problem it teaches</th>
</tr>
</thead>
<tbody><tr>
<td>Item rows</td>
<td>Card, Avatar, Badge, Button</td>
<td>No cascading styles, no <code>truncate</code>, small tap targets</td>
</tr>
<tr>
<td>Quantity stepper</td>
<td>Button, Icon</td>
<td>Icons take props, not classes</td>
</tr>
<tr>
<td>Pickup time</td>
<td>Select, Label</td>
<td>Dropdowns need a portal</td>
</tr>
<tr>
<td>Name field</td>
<td>Input, Label</td>
<td>The keyboard can cover the field</td>
</tr>
<tr>
<td>Own cup toggle</td>
<td>Switch, Label</td>
<td>Making the label text tappable</td>
</tr>
<tr>
<td>Bill</td>
<td>Separator, Text</td>
<td>Digits that don't line up</td>
</tr>
<tr>
<td>Checkout bar</td>
<td>Button, AlertDialog</td>
<td>No <code>position: fixed</code>, and the home indicator</td>
</tr>
</tbody></table>
<p>Here's the finished screen:</p>
<img src="https://cdn.hashnode.com/uploads/covers/5e0f2c2e490269cb30227a2b/a30e05d8-efcb-41ed-ad2c-fd22763d7ea2.png" alt="The finished cart screen in light mode" style="display: block;" width="414" height="896" loading="lazy">

<img src="https://cdn.hashnode.com/uploads/covers/5e0f2c2e490269cb30227a2b/f24bc348-c9a2-4197-92a6-c60479fb3686.png" alt="The finished cart screen in dark mode" style="display: block;" width="414" height="896" loading="lazy">

<p>The complete code is available in the <a href="https://github.com/shadcnstudio/shadcn-react-native-app">GitHub repository</a> if you want to compare your work with the final result.</p>
<h2 id="heading-step-1-create-the-app">Step 1: Create the App</h2>
<p>We can let the React Native Reusables CLI create the initial project for us. It sets up Expo Router, the styling configuration, the theme file, and a few starter components. Run the following command to get started:</p>
<pre><code class="language-bash">pnpm dlx @react-native-reusables/cli@latest init
</code></pre>
<h3 id="heading-answer-the-clis-questions">Answer the CLI's Questions</h3>
<p>The CLI asks four questions.</p>
<p><strong>What is the name of your project?</strong> The name you type becomes the folder name. It suggests <code>my-app</code>.</p>
<p><strong>Select a template.</strong> There are three options, and the one you need isn't the one selected by default:</p>
<img src="https://cdn.hashnode.com/uploads/covers/5e0f2c2e490269cb30227a2b/7ce945cb-ac0e-49f0-990b-c0c2cf956f29.png" alt="The template selection prompt in the terminal" style="display: block;" width="556" height="141" loading="lazy">

<pre><code class="language-plaintext">❯ Minimal (Nativewind)
  Minimal (Uniwind)
  Clerk auth (Nativewind)
</code></pre>
<p>Press the down arrow once and choose <strong>Minimal (Uniwind)</strong>. This is the one choice that's tricky to change later. Nativewind and Uniwind are two different ways to use Tailwind in React Native, and the CLI keeps a separate registry for each one. The components it writes for Uniwind are different from the ones it writes for Nativewind, so the code in this tutorial won't match if you pick Nativewind.</p>
<p><strong>Would you like to install dependencies?</strong> Choose yes, and select the package manager you use.</p>
<p><strong>Would you like to initialize a Git repository?</strong> Choose yes. You're about to replace the starter screen, and having a commit to compare against is helpful.</p>
<h3 id="heading-look-at-the-project-structure">Look at the Project Structure</h3>
<p>The CLI creates the following files:</p>
<pre><code class="language-plaintext">shadcn-react-native-app/
├── app/
│   ├── _layout.tsx        # ThemeProvider, Stack, and the PortalHost
│   ├── +html.tsx          # web only, the root HTML shell
│   ├── +not-found.tsx
│   └── index.tsx          # the starter screen
├── components/ui/
│   ├── button.tsx
│   ├── icon.tsx
│   └── text.tsx
├── lib/
│   ├── theme.ts           # the same palette again, in JavaScript
│   └── utils.ts           # cn()
├── global.css             # the theme tokens
├── components.json        # the shadcn config, same as on the web
├── metro.config.js        # withUniwindConfig
└── uniwind-types.d.ts     # generated, do not edit
</code></pre>
<p>Before moving on, let's take a look at a few files in this structure. You'll use them throughout the tutorial:</p>
<ul>
<li><code>components.json</code> is the same shadcn configuration file used on the web. It tells the CLI where to put components (<code>@/components/ui</code>) and where the <code>cn()</code> helper lives (<code>@/lib/utils</code>).</li>
<li><code>global.css</code> holds your theme tokens, which you'll learn about in Step 2.</li>
<li><code>lib/utils.ts</code> exports <code>cn()</code>, a helper that combines class names and resolves conflicts between them.</li>
<li><code>app/_layout.tsx</code> contains a <code>PortalHost</code> component. It looks like leftover scaffolding, but you must not delete it. Step 7 explains why.</li>
</ul>
<p>Uniwind reads <code>global.css</code> while Metro bundles the app and turns your class strings into React Native style objects. This happens at build time, so a long <code>className</code> string doesn't slow down your app.</p>
<h3 id="heading-run-the-app">Run the App</h3>
<p>Start the development server:</p>
<pre><code class="language-bash">pnpm dev
</code></pre>
<p>Press <code>w</code> to open it in the browser, <code>i</code> for the iOS simulator, or <code>a</code> for Android. The starter screen has a theme toggle in the header, which shows that the theme setup is working.</p>
<p>You can also run a diagnostic command at any point if something seems wrong:</p>
<pre><code class="language-bash">pnpm dlx @react-native-reusables/cli@latest doctor
</code></pre>
<p>It checks your setup and reports which styling library it detects. For this project, the output should be:</p>
<pre><code class="language-plaintext">ℹ Styling Library: Uniwind
✔ All checks passed.
</code></pre>
<p>If it says Nativewind, fix that before you add any components.</p>
<p>Once the setup is working, you should see the starter screen. Try the theme toggle in the header to make sure light and dark mode both work, and check that the console is free of errors:</p>
<img src="https://cdn.hashnode.com/uploads/covers/5e0f2c2e490269cb30227a2b/72fbc819-a026-41cb-824d-6f50b9e88625.png" alt="The starter screen" style="display: block;" width="414" height="896" loading="lazy">

<h2 id="heading-step-2-understand-the-theme-file">Step 2: Understand the Theme File</h2>
<p>Now that the app is running, let's look at its theme setup. The <code>global.css</code> file is where we'll define the colors used by the components. If you've previously kept these values in a <code>colors.ts</code> or <code>theme.ts</code> file, this is the setup that replaces it.</p>
<pre><code class="language-css">@import "tailwindcss";
@import "uniwind";

@import "tw-animate-css";

@theme {
  --radius: 10px;
  --radius-sm: calc(var(--radius) - 4px);
  --radius-md: calc(var(--radius) - 2px);
  --radius-lg: var(--radius);
  --radius-xl: calc(var(--radius) + 4px);

  --spacing-hairline: hairlineWidth();
}

@layer theme {
  :root {
    @variant light {
      --color-background: oklch(1 0 0);
      --color-foreground: oklch(0.145 0 0);
      --color-card: oklch(1 0 0);
      --color-primary: oklch(0.205 0 0);
      --color-muted-foreground: oklch(0.556 0 0);
      --color-border: oklch(0.922 0 0);
      /* the rest of the list */
    }

    @variant dark {
      --color-background: oklch(0.145 0 0);
      --color-foreground: oklch(0.985 0 0);
      --color-card: oklch(0.205 0 0);
      --color-primary: oklch(0.922 0 0);
      --color-muted-foreground: oklch(0.708 0 0);
      --color-border: oklch(1 0 0 / 10%);
      /* the rest of the list */
    }
  }
}
</code></pre>
<p>There are two conventions in this file that you need to know.</p>
<p>First, the <code>--color-</code> prefix creates the class names. When you declare <code>--color-primary</code>, Tailwind automatically creates <code>bg-primary</code>, <code>text-primary</code>, and <code>border-primary</code>. If you declare <code>--primary</code> instead, you only get a CSS variable that nothing uses.</p>
<p>This is important because most shadcn theme generators produce the web format, where the variables are named <code>--primary</code>. If you paste that output without renaming the variables, nothing breaks, but nothing changes either. Step 12 shows you how to convert them.</p>
<p>Second, <code>@variant light</code> and <code>@variant dark</code> replace <code>:root</code> and <code>.dark</code>. On the web, dark mode works by adding a <code>.dark</code> class to the page. A phone has no page to add a class to, so Uniwind manages the switch. When you call <code>Uniwind.setTheme</code>, it swaps the active values. You'll use this in Step 11.</p>
<p>You may also notice that the file uses <code>oklch()</code> colors. Phones don't have a browser to read that format, but Uniwind converts the colors to a format React Native understands while bundling, so you can use modern color syntax anyway.</p>
<h3 id="heading-the-palette-also-exists-in-libthemets">The Palette Also Exists in <code>lib/theme.ts</code></h3>
<p>If you open <code>lib/theme.ts</code>, you'll find the same colors again as a JavaScript object. This duplication is needed because React Navigation, which draws the header and screen background, reads colors from a plain JavaScript object and can't read CSS variables. As a result, you have to keep two copies of your palette in sync. Step 12 shows what happens when they differ.</p>
<h3 id="heading-try-it-change-one-color">Try It: Change One Color</h3>
<p>Let's change one of the tokens to see how the theme works. Update the primary color in the light theme to a value that's easy to notice:</p>
<pre><code class="language-css">--color-primary: oklch(0.6 0.24 25);
</code></pre>
<p>Save the file and look at the starter screen. The <strong>Browse the Docs</strong> button is now red, even though you didn't edit <code>button.tsx</code>:</p>
<img src="https://cdn.hashnode.com/uploads/covers/5e0f2c2e490269cb30227a2b/0d2116eb-9052-40a1-9163-69f1a89dbd14.png" alt="The starter button turned red after changing one token" style="display: block;" width="414" height="896" loading="lazy">

<p>Notice that every component using <code>bg-primary</code> picks up the new color. You only changed one token, but the button updated without touching its component file. Change the value back before continuing.</p>
<h2 id="heading-step-3-read-three-core-components">Step 3: Read Three Core Components</h2>
<p>The starter project already gives us three components: <code>Text</code>, <code>Button</code>, and <code>Icon</code>. I'd take a few minutes to look through them before building the screen. They introduce patterns you'll see again in the other registry components.</p>
<h3 id="heading-the-text-component">The Text Component</h3>
<p>In React Native, styles don't cascade the way they do in CSS. If you set a text color on a <code>View</code>, the text inside it doesn't inherit that color. This is a problem for a component such as <code>&lt;Button variant="destructive"&gt;</code>, which needs its label to be white. The label is a <code>Text</code> component that the Button doesn't control, because it comes in through <code>children</code>. On the web, the Button would simply set a color and let it flow down to the label.</p>
<p>React Native Reusables solves this with React context. This is the code in <code>components/ui/text.tsx</code>:</p>
<pre><code class="language-tsx">const TextClassContext = React.createContext&lt;string | undefined&gt;(undefined);

function Text({ className, asChild = false, variant = 'default', ...props }) {
  const textClass = React.useContext(TextClassContext);
  const Component = asChild ? Slot : RNText;
  return (
    &lt;Component
      className={cn(textVariants({ variant }), textClass, className)}
      role={variant ? ROLE[variant] : undefined}
      aria-level={variant ? ARIA_LEVEL[variant] : undefined}
      {...props}
    /&gt;
  );
}
</code></pre>
<p>A parent component, such as Button, puts a class string into the context. Every <code>Text</code> inside it reads that string and applies it. Your own <code>className</code> still wins because it comes last in the <code>cn()</code> call.</p>
<p>The <code>Text</code> component also has a <code>variant</code> prop with options like <code>h1</code> to <code>h4</code>, <code>p</code>, <code>code</code>, <code>lead</code>, <code>large</code>, <code>small</code>, and <code>muted</code>. For example, <code>&lt;Text variant="muted"&gt;</code> gives you the mobile version of <code>text-muted-foreground text-sm</code>. The variants also set the <code>role</code> and <code>aria-level</code> props, so screen readers announce headings correctly without any extra work.</p>
<h3 id="heading-the-button-component">The Button Component</h3>
<p>The Button in <code>components/ui/button.tsx</code> uses <code>cva</code> (class-variance-authority) the same way the web version does. Here's a shortened version:</p>
<pre><code class="language-tsx">const buttonVariants = cva(
  cn(
    'group shrink-0 flex-row items-center justify-center gap-2 rounded-md shadow-none',
    Platform.select({
      web: "focus-visible:border-ring focus-visible:ring-ring/50 ... transition-all",
    })
  ),
  {
    variants: {
      variant: {
        default: cn(
          'bg-primary active:bg-primary/90 shadow-sm shadow-black/5',
          Platform.select({ web: 'hover:bg-primary/90' })
        ),
        /* ... */
      },
    },
  }
);
</code></pre>
<p>There are four differences from the web version:</p>
<ul>
<li><code>flex-row</code> <strong>is written out:</strong> React Native lays out children in a column by default, which is the opposite of CSS. Every horizontal layout in this tutorial includes <code>flex-row</code> for that reason.</li>
<li><code>active:</code> <strong>replaces</strong> <code>hover:</code><strong>:</strong> A finger can't really hover, so <code>active:</code> is the pressed state on a phone.</li>
<li><strong>Web-only classes are wrapped in</strong> <code>Platform.select</code><strong>:</strong> Classes such as <code>focus-visible:ring-[3px]</code> mean nothing in React Native, so they're only included in the web build.</li>
<li><strong>A</strong> <code>TextClassContext.Provider</code> <strong>wraps the</strong> <code>Pressable</code><strong>:</strong> This uses the context from the previous section, and it's why <code>&lt;Button variant="destructive"&gt;&lt;Text&gt;Delete&lt;/Text&gt;&lt;/Button&gt;</code> has white text automatically.</li>
</ul>
<h3 id="heading-the-icon-component">The Icon Component</h3>
<p>Icons from <code>lucide-react-native</code> take <code>color</code> and <code>size</code> as props, not as class names. The <code>Icon</code> component in <code>components/ui/icon.tsx</code> teaches Uniwind how to convert one into the other:</p>
<pre><code class="language-tsx">const StyledIcon = withUniwind(IconImpl, {
  size: { fromClassName: 'className', styleProperty: 'width' },
  color: { fromClassName: 'className', styleProperty: 'color' },
});
</code></pre>
<p>This code reads the <code>width</code> from the class string and passes it as <code>size</code>, and it reads the <code>color</code> and passes it as <code>color</code>. That's why <code>&lt;Icon as={PlusIcon} className="size-4 text-muted-foreground" /&gt;</code> works the way you would expect. <code>withUniwind</code> is useful any time you use a third-party component that takes props where you want to use classes.</p>
<p>You don't need to run anything for this step. The important part is understanding what <code>TextClassContext</code> is doing. Once that clicks, the other components in the registry are much easier to follow.</p>
<h2 id="heading-step-4-add-the-components-you-need">Step 4: Add the Components You Need</h2>
<p>We already have three components from the template. For the checkout screen, we need a few more. The CLI can add all of them in one go:</p>
<pre><code class="language-bash">pnpm dlx @react-native-reusables/cli@latest add card separator input label select switch badge alert-dialog avatar
</code></pre>
<p>The CLI detects that you're using Uniwind and writes the matching versions. It also installs any required <code>@rn-primitives</code> packages and adds a file called <code>native-only-animated-view.tsx</code>, which Select and AlertDialog use for their animations.</p>
<p>The output looks like this:</p>
<pre><code class="language-plaintext">ℹ Styling Library: Uniwind
✔ Created 10 files:
  - components/ui/separator.tsx
  - components/ui/input.tsx
  - components/ui/label.tsx
  - components/ui/switch.tsx
  - components/ui/avatar.tsx
  - components/ui/native-only-animated-view.tsx
  - components/ui/card.tsx
  - components/ui/badge.tsx
  - components/ui/select.tsx
  - components/ui/alert-dialog.tsx
ℹ Skipped 3 files: (files might be identical, use --overwrite to overwrite)
  - components/ui/text.tsx
  - components/ui/icon.tsx
  - components/ui/button.tsx
</code></pre>
<p>The CLI created ten files, which is more than the nine you asked for, because <code>native-only-animated-view.tsx</code> is a dependency of Select and AlertDialog. It skipped the three files that the template already gave you, so it does not overwrite your copies. This is the "you own the file" idea at work.</p>
<p>Run <code>pnpm dev</code> again to make sure the app still starts. The <code>components/ui/</code> folder should now contain thirteen files.</p>
<h2 id="heading-step-5-set-up-the-data-and-the-screen">Step 5: Set Up the Data and the Screen</h2>
<p>Before we start building the UI, let's add the sample menu data and decide where the screen state will live. I'm going to store prices in cents rather than floating-point numbers. This avoids calculation results such as <code>$4.7499999</code>.</p>
<p>We'll also keep the state in the main screen component and pass the relevant values down as props. That way, changing an item quantity or selecting the own-cup option automatically updates the bill.</p>
<p>Create <code>lib/menu.ts</code>:</p>
<pre><code class="language-tsx">export type CartItem = {
  id: string;
  name: string;
  detail: string;
  size?: 'Small' | 'Medium' | 'Large';
  emoji: string;
  /** Cents. Money in floats is how you end up charging someone $4.7499999. */
  unitPrice: number;
  qty: number;
};

export const INITIAL_CART: CartItem[] = [
  {
    id: 'flat-white',
    name: 'Flat white',
    detail: 'Oat milk, extra shot',
    size: 'Medium',
    emoji: '☕️',
    unitPrice: 475,
    qty: 2,
  },
  {
    id: 'cold-brew',
    name: 'Cold brew',
    detail: 'Hold the ice',
    size: 'Large',
    emoji: '🧋',
    unitPrice: 525,
    qty: 1,
  },
  {
    id: 'croissant',
    name: 'Almond croissant',
    detail: 'Warmed',
    emoji: '🥐',
    unitPrice: 390,
    qty: 1,
  },
];

export const PICKUP_TIMES = [
  { value: 'asap', label: 'As soon as it is ready' },
  { value: '15', label: 'In 15 minutes' },
  { value: '30', label: 'In 30 minutes' },
  { value: '60', label: 'In an hour' },
];

export const CUP_DISCOUNT = 25;
export const TAX_RATE = 0.0825;

export function money(cents: number) {
  const sign = cents &lt; 0 ? '-' : '';
  return `${sign}$${(Math.abs(cents) / 100).toFixed(2)}`;
}

export function billFor(items: CartItem[], ownCup: boolean) {
  const subtotal = items.reduce((sum, item) =&gt; sum + item.unitPrice * item.qty, 0);
  const discount = ownCup &amp;&amp; subtotal &gt; 0 ? CUP_DISCOUNT : 0;
  const tax = Math.round((subtotal - discount) * TAX_RATE);

  return { subtotal, discount, tax, total: subtotal - discount + tax };
}
</code></pre>
<p>The <code>PICKUP_TIMES</code> list is in this file instead of inside a component because two different components need it. You'll see why in Step 7.</p>
<h3 id="heading-the-screen-layout">The Screen Layout</h3>
<p>This is basically how <code>app/index.tsx</code> looks. The parts that don't exist yet are left as comments, and you'll write the full file later in Step 10.</p>
<pre><code class="language-tsx">&lt;View className="bg-background flex-1"&gt;
  &lt;ScrollView
    className="flex-1"
    contentContainerClassName="gap-4 p-4 pb-8"
    keyboardShouldPersistTaps="handled"
    automaticallyAdjustKeyboardInsets&gt;
    {/* the three cards */}
  &lt;/ScrollView&gt;

  &lt;CheckoutBar {...} /&gt;
&lt;/View&gt;
</code></pre>
<p>There are three details in this layout that you should examine more closely:</p>
<ul>
<li>First, <code>className</code> on a <code>ScrollView</code> styles the scroll container, not its content. This is the class name version of the <code>style</code> and <code>contentContainerStyle</code> split in React Native. If you put padding in <code>className</code>, it gets clipped, and <code>gap</code> has no effect. Use <code>contentContainerClassName</code> for anything that should apply to the content. Uniwind adds this prop to <code>ScrollView</code>.</li>
<li>There's no <code>space-y-4</code>. In CSS, <code>space-y-*</code> works by selecting siblings, and React Native has no selectors. Use <code>gap-4</code> on the parent instead, which React Native supports on iOS, Android, and the web.</li>
<li><code>keyboardShouldPersistTaps="handled"</code> keeps taps working while the keyboard is open. Without it, the first tap after the keyboard appears only closes the keyboard, so the user has to tap twice. <code>automaticallyAdjustKeyboardInsets</code> is an iOS feature that scrolls the content so the focused input isn't hidden behind the keyboard.</li>
</ul>
<p>At this stage, you should see only a header with the new title and an empty page below it:</p>
<img src="https://cdn.hashnode.com/uploads/covers/5e0f2c2e490269cb30227a2b/02188707-8809-4cc8-bc1d-1a79330bebd3.png" alt="An empty screen with the new header title" style="display: block;" width="414" height="896" loading="lazy">

<h2 id="heading-step-6-build-the-order-rows">Step 6: Build the Order Rows</h2>
<p>The order row has quite a bit going on in a small space: an avatar, product name, size badge, price, and quantity controls. Long names make this especially tricky on a phone, so we'll handle the layout carefully.</p>
<p>Create <code>components/cart/order-row.tsx</code>:</p>
<pre><code class="language-tsx">import { Avatar, AvatarFallback } from '@/components/ui/avatar';
import { Badge } from '@/components/ui/badge';
import { Button } from '@/components/ui/button';
import { Icon } from '@/components/ui/icon';
import { Text } from '@/components/ui/text';
import { money, type CartItem } from '@/lib/menu';
import { MinusIcon, PlusIcon, Trash2Icon } from 'lucide-react-native';
import { View } from 'react-native';

type OrderRowProps = {
  item: CartItem;
  onChangeQty: (id: string, qty: number) =&gt; void;
};

export function OrderRow({ item, onChangeQty }: OrderRowProps) {
  const lastOne = item.qty &lt;= 1;

  return (
    &lt;View className="flex-row gap-3"&gt;
      &lt;Avatar alt={item.name} className="size-14 rounded-2xl"&gt;
        &lt;AvatarFallback className="bg-muted rounded-2xl"&gt;
          &lt;Text className="text-2xl"&gt;{item.emoji}&lt;/Text&gt;
        &lt;/AvatarFallback&gt;
      &lt;/Avatar&gt;

      &lt;View className="flex-1 gap-2"&gt;
        &lt;View className="flex-row items-start gap-3"&gt;
          &lt;View className="flex-1 gap-1"&gt;
            &lt;View className="flex-row items-center gap-2"&gt;
              &lt;Text numberOfLines={1} className="shrink font-medium"&gt;
                {item.name}
              &lt;/Text&gt;
              {item.size ? (
                &lt;Badge variant="secondary"&gt;
                  &lt;Text&gt;{item.size}&lt;/Text&gt;
                &lt;/Badge&gt;
              ) : null}
            &lt;/View&gt;
            &lt;Text numberOfLines={1} variant="muted"&gt;
              {item.detail}
            &lt;/Text&gt;
          &lt;/View&gt;
          &lt;Text className="text-sm font-medium tabular-nums"&gt;
            {money(item.unitPrice * item.qty)}
          &lt;/Text&gt;
        &lt;/View&gt;

        &lt;View className="border-border flex-row items-center gap-1 self-start rounded-full border p-0.5"&gt;
          &lt;Button
            size="icon"
            variant="ghost"
            hitSlop={8}
            className="size-7 rounded-full"
            accessibilityLabel={lastOne ? `Remove ${item.name}` : `One fewer ${item.name}`}
            onPress={() =&gt; onChangeQty(item.id, item.qty - 1)}&gt;
            &lt;Icon as={lastOne ? Trash2Icon : MinusIcon} className="size-4" /&gt;
          &lt;/Button&gt;
          &lt;Text className="w-5 text-center text-sm font-medium tabular-nums"&gt;{item.qty}&lt;/Text&gt;
          &lt;Button
            size="icon"
            variant="ghost"
            hitSlop={8}
            className="size-7 rounded-full"
            accessibilityLabel={`One more ${item.name}`}
            onPress={() =&gt; onChangeQty(item.id, item.qty + 1)}&gt;
            &lt;Icon as={PlusIcon} className="size-4" /&gt;
          &lt;/Button&gt;
        &lt;/View&gt;
      &lt;/View&gt;
    &lt;/View&gt;
  );
}
</code></pre>
<p>A few details in this component deserve a closer look.</p>
<p>First, <code>Avatar</code> requires the <code>alt</code> prop. TypeScript won't compile without it. The value becomes the accessibility label, so a screen reader says "Flat white" instead of just "image".</p>
<p>The radius is repeated on the avatar fallback. <code>Avatar</code> and <code>AvatarFallback</code> are each <code>rounded-full</code> by default. If you only set <code>rounded-2xl</code> on <code>Avatar</code>, the emoji background stays a circle and pokes out of the rounded square.</p>
<p>You should also use <code>numberOfLines={1}</code> instead of <code>truncate</code>. Tailwind's <code>truncate</code> relies on <code>text-overflow: ellipsis</code>, which React Native doesn't support, and Uniwind doesn't convert it. The class compiles to nothing, so a long product name pushes the price off the screen. The <code>numberOfLines</code> prop is the React Native way to do this, and it also works in the web build.</p>
<p>The name has <code>shrink</code> and its column has <code>flex-1</code>. Without <code>shrink</code>, a long name won't get smaller and will push the badge out of the row. This is regular Flexbox behavior, but it shows up more on a phone because there's less width to work with.</p>
<p><code>hitSlop={8}</code> makes small buttons easier to tap. Apple recommends touch targets of at least 44 points and Android recommends 48dp, but a <code>size-7</code> button is only 28 points wide. The <code>hitSlop</code> prop makes the touchable area larger without changing how the button looks. There's no CSS equivalent.</p>
<p>Finally, <code>tabular-nums</code> keeps digits the same width. In most fonts, the digit <code>1</code> is narrower than <code>8</code>, so prices would shift sideways every time the quantity changes. Uniwind converts <code>tabular-nums</code> to React Native's <code>fontVariant</code>, so it works on iOS, Android, and the web.</p>
<p>After adding this component and rendering it inside a Card (which you'll do in Step 10), you should see three rows:</p>
<img src="https://cdn.hashnode.com/uploads/covers/5e0f2c2e490269cb30227a2b/d361c2e7-8eaa-466d-aed1-7b162b6ace95.png" alt="The order rows inside a card" style="display: block;" width="414" height="896" loading="lazy">

<p>Tapping plus on the flat white should change its price from <code>$9.50</code> to <code>$14.25</code>. Tapping the trash icon on an item with a quantity of one should remove the row. The minus button turns into a trash icon whenever the quantity is one.</p>
<h2 id="heading-step-7-build-the-pickup-options">Step 7: Build the Pickup Options</h2>
<p>The pickup card brings together three controls: a Select, an Input, and a Switch. The input and switch are fairly straightforward. The Select needs a little more attention because it has three platform-related quirks, and two of them can fail silently.</p>
<p>Create <code>components/cart/pickup-card.tsx</code>:</p>
<pre><code class="language-tsx">import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import {
  Select,
  SelectContent,
  SelectItem,
  SelectTrigger,
  SelectValue,
} from '@/components/ui/select';
import { Switch } from '@/components/ui/switch';
import { Text } from '@/components/ui/text';
import { PICKUP_TIMES } from '@/lib/menu';
import { View } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';

type PickupCardProps = {
  pickupValue: string;
  onPickupValueChange: (value: string) =&gt; void;
  name: string;
  onNameChange: (value: string) =&gt; void;
  ownCup: boolean;
  onOwnCupChange: (value: boolean) =&gt; void;
};

export function PickupCard({
  pickupValue,
  onPickupValueChange,
  name,
  onNameChange,
  ownCup,
  onOwnCupChange,
}: PickupCardProps) {
  const insets = useSafeAreaInsets();
  // Look the label up from our own data. The Option handed back by onValueChange
  // does not carry a usable label on web. See the note below.
  const selected = PICKUP_TIMES.find((time) =&gt; time.value === pickupValue);
  const contentInsets = {
    top: insets.top,
    bottom: insets.bottom,
    left: 16,
    right: 16,
  };

  return (
    &lt;View className="gap-5"&gt;
      &lt;View className="gap-2"&gt;
        &lt;Label nativeID="pickup-time"&gt;Pickup time&lt;/Label&gt;
        &lt;Select
          value={selected}
          onValueChange={(option) =&gt; {
            if (option) {
              onPickupValueChange(option.value);
            }
          }}&gt;
          &lt;SelectTrigger className="w-full" aria-labelledby="pickup-time"&gt;
            &lt;SelectValue placeholder="Pick a time" /&gt;
          &lt;/SelectTrigger&gt;
          &lt;SelectContent insets={contentInsets} className="w-full"&gt;
            {PICKUP_TIMES.map((time) =&gt; (
              &lt;SelectItem key={time.value} value={time.value} label={time.label} /&gt;
            ))}
          &lt;/SelectContent&gt;
        &lt;/Select&gt;
      &lt;/View&gt;

      &lt;View className="gap-2"&gt;
        &lt;Label nativeID="order-name"&gt;Name for the order&lt;/Label&gt;
        &lt;Input
          aria-labelledby="order-name"
          value={name}
          onChangeText={onNameChange}
          placeholder="Who is picking it up?"
          autoCapitalize="words"
          autoComplete="name"
          returnKeyType="done"
        /&gt;
      &lt;/View&gt;

      &lt;View className="flex-row items-center justify-between gap-4"&gt;
        &lt;View className="flex-1 gap-1"&gt;
          &lt;Label nativeID="own-cup" onPress={() =&gt; onOwnCupChange(!ownCup)}&gt;
            Bringing my own cup
          &lt;/Label&gt;
          &lt;Text variant="muted"&gt;Takes 25¢ off and saves a lid.&lt;/Text&gt;
        &lt;/View&gt;
        &lt;Switch nativeID="own-cup" checked={ownCup} onCheckedChange={onOwnCupChange} /&gt;
      &lt;/View&gt;
    &lt;/View&gt;
  );
}
</code></pre>
<h3 id="heading-problem-1-portals-and-the-portalhost">Problem 1: Portals and the PortalHost</h3>
<p>When a dropdown opens, it needs to appear above the other content on the screen. For that reason, <code>SelectContent</code> isn't rendered in the same place where you declare it in the component tree. It uses <code>@rn-primitives/portal</code> to render the content in another part of the app. This technique is called a portal.</p>
<p>On the web, a portal renders into <code>document.body</code>, and every page has one. React Native has nothing like that. So the portal package keeps a list of portal contents in memory, and a component called <code>PortalHost</code> reads that list and displays it. This is a simplified version of that code from <code>node_modules/@rn-primitives/portal/dist/index.js</code>:</p>
<pre><code class="language-jsx">var DEFAULT_PORTAL_HOST = "INTERNAL_PRIMITIVE_DEFAULT_HOST_NAME";
var updatePortal = (hostName, name, children) =&gt; { /* writes into the map */ };
function PortalHost({ name = DEFAULT_PORTAL_HOST }) { /* reads the map */ }
</code></pre>
<p>If no <code>PortalHost</code> is mounted, the content is saved but never displayed. The dropdown opens into nothing, and you get no error or warning.</p>
<p>The template already includes a <code>PortalHost</code> at the bottom of the root layout:</p>
<pre><code class="language-tsx">&lt;ThemeProvider value={NAV_THEME[theme ?? 'light']}&gt;
  &lt;StatusBar style={theme === 'dark' ? 'light' : 'dark'} /&gt;
  &lt;Stack /&gt;
  &lt;PortalHost /&gt;
&lt;/ThemeProvider&gt;
</code></pre>
<p>It looks like unnecessary code, but you need to keep it. The AlertDialog in Step 10 uses it too.</p>
<h3 id="heading-problem-2-safe-area-insets">Problem 2: Safe Area Insets</h3>
<p>There's another issue to consider when showing a dropdown on a phone. Parts of the screen are reserved for the operating system, such as the area around the notch and the home indicator. If a dropdown opens near the bottom of the screen, one of its options could appear underneath the home indicator. In that area, a tap may be handled by the operating system instead of your app.</p>
<p>To avoid this, pass the safe area insets to the content:</p>
<pre><code class="language-tsx">const insets = useSafeAreaInsets();
const contentInsets = { top: insets.top, bottom: insets.bottom, left: 16, right: 16 };

&lt;SelectContent insets={contentInsets} className="w-full"&gt;
</code></pre>
<p>The <code>insets</code> prop is part of <code>PositionedContentProps</code> in <code>@rn-primitives/types</code>, so every positioned component in the registry accepts it, including Popover, DropdownMenu, HoverCard, Tooltip, and Select. It's a good habit to pass it every time.</p>
<h3 id="heading-problem-3-the-select-value-is-an-object">Problem 3: The Select Value Is an Object</h3>
<p>One more thing to watch out for is the value returned by <code>onValueChange</code>. It may look like you're selecting a string, but the callback returns an <code>Option</code> object:</p>
<pre><code class="language-tsx">type Option = { value: string; label: string } | undefined;
</code></pre>
<p>This causes a bug that only appears on one platform. If you store the whole <code>Option</code> in state and show <code>option.label</code> later, such as in a confirmation dialog, it displays correctly on a phone ("In 30 minutes") but incorrectly in the browser ("30").</p>
<p>The reason is in the primitive's source code. This is the native version, from <code>select.js</code>:</p>
<pre><code class="language-jsx">onValueChange({ value: itemValue, label });
</code></pre>
<p>And this is the web version, from <code>select.web.js</code>. It uses Radix, which only returns a value:</p>
<pre><code class="language-jsx">onValueChange({ value: val, label: val });
</code></pre>
<p>So the label is correct on native, but on the web it's a copy of the value. If you only test in a simulator, you won't notice this problem.</p>
<p>The fix is to keep only the value in state and look up the label from your own list:</p>
<pre><code class="language-tsx">const selected = PICKUP_TIMES.find((time) =&gt; time.value === pickupValue);
</code></pre>
<p>This is why <code>PICKUP_TIMES</code> is in <code>lib/menu.ts</code>. The pickup card needs it to build the options, and the main screen needs it to write the confirmation message.</p>
<h3 id="heading-making-the-label-tappable">Making the Label Tappable</h3>
<p>The switch itself is quite small, so users may tap the label next to it instead. It makes sense to let that label toggle the switch as well. You can do that by adding an <code>onPress</code> handler to the <code>Label</code>:</p>
<pre><code class="language-tsx">&lt;Label nativeID="own-cup" onPress={() =&gt; onOwnCupChange(!ownCup)}&gt;
  Bringing my own cup
&lt;/Label&gt;
&lt;Switch nativeID="own-cup" checked={ownCup} onCheckedChange={onOwnCupChange} /&gt;
</code></pre>
<p>Giving both elements the same <code>nativeID</code> connects them for screen readers. The <code>onPress</code> on the <code>Label</code> is what makes the text toggle the switch, because React Native has no automatic <code>&lt;label for&gt;</code> behavior.</p>
<p>While you're here, open <code>components/ui/switch.tsx</code>. On the web, shadcn colors a switch with <code>data-[state=checked]:bg-primary</code>, which reads an attribute set in the DOM. React Native has no <code>data-*</code> attributes, so the component checks the prop in JavaScript:</p>
<pre><code class="language-tsx">props.checked ? 'bg-primary' : 'bg-input dark:bg-input/80',
</code></pre>
<p>The result is the same. Keep this in mind if you copy a <code>data-[state=...]</code> selector from a web example and it has no effect.</p>
<h3 id="heading-keyboard-props-for-the-name-field">Keyboard Props for the Name Field</h3>
<p><code>Input</code> is a <code>TextInput</code> with your border and radius applied. You should set these four props on every text input:</p>
<ul>
<li><code>autoCapitalize="words"</code> capitalizes each word, which suits a name.</li>
<li><code>autoComplete="name"</code> lets the operating system offer to fill in the name.</li>
<li><code>returnKeyType="done"</code> changes the return key label to "Done".</li>
<li><code>keyboardType="number-pad"</code> shows a numeric keyboard when you need digits.</li>
</ul>
<p>Together with <code>automaticallyAdjustKeyboardInsets</code> on the ScrollView from Step 5, this keeps the field visible while the keyboard is open. If you need more control, <code>react-native-keyboard-controller</code> is already a dependency of the template, and it provides <code>KeyboardAwareScrollView</code> and <code>KeyboardProvider</code>.</p>
<p>When you open the dropdown, it should appear right under the trigger at the same width, with a check mark next to the current value:</p>
<img src="https://cdn.hashnode.com/uploads/covers/5e0f2c2e490269cb30227a2b/d5234c02-19f7-4938-b889-24be5f13c175.png" alt="The open pickup time dropdown" style="display: block;" width="414" height="896" loading="lazy">

<p>Try picking a time and check that the trigger updates. Tap the words "Bringing my own cup" and confirm the switch flips. Type in the name field and confirm the keyboard doesn't cover it. If the dropdown opens and shows nothing, check your <code>PortalHost</code>.</p>
<h2 id="heading-step-8-build-the-bill-component">Step 8: Build the Bill Component</h2>
<p>The bill component is pretty small, but there are two details you should pay particular attention to here, especially when the values change while someone is editing their order.</p>
<p>Create <code>components/cart/bill.tsx</code>:</p>
<pre><code class="language-tsx">import { Separator } from '@/components/ui/separator';
import { Text } from '@/components/ui/text';
import { cn } from '@/lib/utils';
import { money } from '@/lib/menu';
import { View } from 'react-native';

type BillProps = {
  subtotal: number;
  discount: number;
  tax: number;
  total: number;
};

function Line({ label, value, tone }: { label: string; value: number; tone?: 'muted' | 'credit' }) {
  return (
    &lt;View className="flex-row items-center justify-between"&gt;
      &lt;Text className={cn('text-sm', tone === 'muted' &amp;&amp; 'text-muted-foreground')}&gt;{label}&lt;/Text&gt;
      &lt;Text
        className={cn(
          'text-sm tabular-nums',
          tone === 'muted' &amp;&amp; 'text-muted-foreground',
          tone === 'credit' &amp;&amp; 'text-foreground'
        )}&gt;
        {money(value)}
      &lt;/Text&gt;
    &lt;/View&gt;
  );
}

export function Bill({ subtotal, discount, tax, total }: BillProps) {
  return (
    &lt;View className="gap-2"&gt;
      &lt;Line label="Subtotal" value={subtotal} tone="muted" /&gt;
      {discount &gt; 0 ? &lt;Line label="Own cup" value={-discount} tone="credit" /&gt; : null}
      &lt;Line label="Tax" value={tax} tone="muted" /&gt;
      &lt;Separator className="my-1" /&gt;
      &lt;View className="flex-row items-center justify-between"&gt;
        &lt;Text className="font-medium"&gt;Total&lt;/Text&gt;
        &lt;Text className="text-lg font-semibold tabular-nums"&gt;{money(total)}&lt;/Text&gt;
      &lt;/View&gt;
    &lt;/View&gt;
  );
}
</code></pre>
<p>First, use <code>tabular-nums</code> on every number. Right-aligned prices in a proportional font don't line up at the decimal point, and using <code>tabular-nums</code> fixes that, as in the order rows.</p>
<p>Second, only show the discount row when it applies. The code uses <code>{discount &gt; 0 ? &lt;Line /&gt; : null}</code> instead of <code>{discount &amp;&amp; &lt;Line /&gt;}</code>. In JSX, if the left side of <code>&amp;&amp;</code> is the number <code>0</code>, React renders the <code>0</code>. In React Native, a bare number outside a <code>Text</code> component throws the error <code>Text strings must be rendered within a &lt;Text&gt; component</code>. Using a boolean check and returning <code>null</code> avoids this whole category of bugs.</p>
<p>To test it, turn on the own cup switch and scroll down. An <strong>Own cup</strong> line should appear with <code>-$0.25</code>, and the tax should change from <code>$1.54</code> to <code>$1.52</code>, because tax is calculated on the discounted subtotal:</p>
<img src="https://cdn.hashnode.com/uploads/covers/5e0f2c2e490269cb30227a2b/5fd0c79e-fcf4-4d7e-9129-bfb1e4d120d5.png" alt="The bill with the own cup discount applied" style="display: block;" width="414" height="896" loading="lazy">

<p>The total changes from <code>$20.19</code> to <code>$19.92</code>, which is 27 cents lower instead of 25. The extra two cents come from the lower tax.</p>
<h2 id="heading-step-9-build-the-fixed-checkout-bar">Step 9: Build the Fixed Checkout Bar</h2>
<p>I want the total and checkout button to remain visible while the user scrolls through the cart. On the web, you might reach for <code>position: sticky</code> and <code>bottom: 0</code>. React Native doesn't work that way, but we can get the same result with a simple flex layout.</p>
<p>You can get the same result with Flexbox. This is the layout from Step 5 again:</p>
<pre><code class="language-tsx">&lt;View className="bg-background flex-1"&gt;
  &lt;ScrollView className="flex-1" ...&gt;{/* content */}&lt;/ScrollView&gt;
  &lt;CheckoutBar ... /&gt;
&lt;/View&gt;
</code></pre>
<p>The outer <code>View</code> is a column. The <code>ScrollView</code> has <code>flex-1</code>, so it takes all the leftover height. The checkout bar is a sibling placed after it, so it sits at the bottom and doesn't scroll. You don't need any positioning or z-index.</p>
<h3 id="heading-handling-the-home-indicator">Handling the Home Indicator</h3>
<p>On phones without a home button, the bottom 34 points or so belong to the system. A button drawn there is hard or impossible to press. To avoid this, add the bottom safe area inset as padding.</p>
<pre><code class="language-tsx">const insets = useSafeAreaInsets();

&lt;View
  className="border-border bg-background flex-row items-center gap-4 border-t px-4 pt-3"
  style={{ paddingBottom: insets.bottom + 12 }}&gt;
</code></pre>
<p>The bottom padding is an inline <code>style</code> instead of a class because its value depends on the device and is only known when the app runs. Using <code>className</code> and <code>style</code> on the same element is fine, and this is the case it's meant for.</p>
<p>On devices with no gesture bar, and in a browser tab, <code>insets.bottom</code> is 0, so the extra <code>12</code> keeps the bar from looking cramped.</p>
<p>Create the full component in <code>components/cart/checkout-bar.tsx</code>. It includes the confirmation dialog, which Step 10 explains.</p>
<pre><code class="language-tsx">import {
  AlertDialog,
  AlertDialogAction,
  AlertDialogCancel,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogTitle,
  AlertDialogTrigger,
} from '@/components/ui/alert-dialog';
import { Button } from '@/components/ui/button';
import { Icon } from '@/components/ui/icon';
import { Text } from '@/components/ui/text';
import { money } from '@/lib/menu';
import * as Haptics from 'expo-haptics';
import { ArrowRightIcon } from 'lucide-react-native';
import { View } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';

type CheckoutBarProps = {
  total: number;
  itemCount: number;
  pickupLabel: string;
  name: string;
  onConfirm: () =&gt; void;
};

export function CheckoutBar({ total, itemCount, pickupLabel, name, onConfirm }: CheckoutBarProps) {
  const insets = useSafeAreaInsets();
  const empty = itemCount === 0;

  function confirm() {
    // expo-haptics ships a web implementation that falls back to navigator.vibrate,
    // so this needs no platform guard.
    Haptics.notificationAsync(Haptics.NotificationFeedbackType.Success);
    onConfirm();
  }

  return (
    &lt;View
      className="border-border bg-background flex-row items-center gap-4 border-t px-4 pt-3"
      style={{ paddingBottom: insets.bottom + 12 }}&gt;
      &lt;View className="flex-1"&gt;
        &lt;Text variant="muted" className="text-xs"&gt;
          {empty ? 'Nothing in the cart' : `${itemCount} ${itemCount === 1 ? 'item' : 'items'}`}
        &lt;/Text&gt;
        &lt;Text className="text-xl font-semibold tabular-nums"&gt;{money(total)}&lt;/Text&gt;
      &lt;/View&gt;

      &lt;AlertDialog&gt;
        &lt;AlertDialogTrigger asChild&gt;
          &lt;Button size="lg" disabled={empty}&gt;
            &lt;Text&gt;Place order&lt;/Text&gt;
            &lt;Icon as={ArrowRightIcon} /&gt;
          &lt;/Button&gt;
        &lt;/AlertDialogTrigger&gt;
        &lt;AlertDialogContent&gt;
          &lt;AlertDialogHeader&gt;
            &lt;AlertDialogTitle&gt;Send this to the counter?&lt;/AlertDialogTitle&gt;
            &lt;AlertDialogDescription&gt;
              {`${money(total)} for ${name.trim() || 'pickup'}, ${pickupLabel.toLowerCase()}. We start making it right away, so it cannot be cancelled after this.`}
            &lt;/AlertDialogDescription&gt;
          &lt;/AlertDialogHeader&gt;
          &lt;AlertDialogFooter&gt;
            &lt;AlertDialogCancel&gt;
              &lt;Text&gt;Not yet&lt;/Text&gt;
            &lt;/AlertDialogCancel&gt;
            &lt;AlertDialogAction onPress={confirm}&gt;
              &lt;Text&gt;Send it&lt;/Text&gt;
            &lt;/AlertDialogAction&gt;
          &lt;/AlertDialogFooter&gt;
        &lt;/AlertDialogContent&gt;
      &lt;/AlertDialog&gt;
    &lt;/View&gt;
  );
}
</code></pre>
<h3 id="heading-a-note-on-thin-borders">A Note on Thin Borders</h3>
<p><code>border-t</code> draws a line that's one logical point thick, which is two or three physical pixels on most modern screens. Next to a true one-pixel line, it looks heavy. React Native's <code>StyleSheet.hairlineWidth</code> gives you the thinnest line the screen can draw, and the template connects it to Tailwind with this line in <code>global.css</code>:</p>
<pre><code class="language-css">--spacing-hairline: hairlineWidth();
</code></pre>
<p>This adds <code>hairline</code> to Tailwind's spacing scale, so <code>h-hairline</code> gives you a divider that's one physical pixel tall. The Common Mistakes section later explains one catch when you try to use it as an override.</p>
<p>That's the checkout bar in place. Scroll to the bottom of the screen and check that it stays below the bill:</p>
<img src="https://cdn.hashnode.com/uploads/covers/5e0f2c2e490269cb30227a2b/a0c4a55c-a723-4a00-b6ff-c46e75c27b30.png" alt="The checkout bar at the bottom after scrolling down" style="display: block;" width="414" height="896" loading="lazy">

<p>Scroll back to the top and the bar stays in the same place:</p>
<img src="https://cdn.hashnode.com/uploads/covers/5e0f2c2e490269cb30227a2b/5af1750b-9b8c-422d-9273-6b2321096e73.png" alt="The checkout bar at the bottom after scrolling up" style="display: block;" width="414" height="896" loading="lazy">

<p>On a phone with a notch, the button should be above the gesture bar. If you remove all items with the trash buttons, the button should be disabled and the label should say "Nothing in the cart".</p>
<h2 id="heading-step-10-add-the-confirmation-and-put-the-screen-together">Step 10: Add the Confirmation and Put the Screen Together</h2>
<p>The checkout bar already contains the confirmation dialog. Before putting the full screen together, there are two differences between the React Native implementation and the web version that are worth looking at.</p>
<h3 id="heading-1-it-also-needs-the-portalhost">1. It Also Needs the <code>PortalHost</code></h3>
<p>On iOS, it also wraps itself in <code>FullWindowOverlay</code> from <code>react-native-screens</code>, so it draws above the native navigation header instead of under it. This is handled inside <code>alert-dialog.tsx</code>, which is why that file imports something that looks unrelated.</p>
<h3 id="heading-2-the-footer-reverses-its-order-on-phones">2. The Footer Reverses its Order on Phones</h3>
<p><code>AlertDialogFooter</code> uses <code>flex-col-reverse</code> and only becomes a row at the <code>sm:</code> breakpoint. On a phone, the button you write last is shown on top. Writing Cancel first and Action second puts the confirm button where the thumb is and the cancel button below it.</p>
<img src="https://cdn.hashnode.com/uploads/covers/5e0f2c2e490269cb30227a2b/0187ff24-1e34-414c-8189-e6f816f64d48.png" alt="The confirmation dialog" style="display: block;" width="414" height="896" loading="lazy">

<h3 id="heading-haptics">Haptics</h3>
<p>When the customer confirms the order, the <code>confirm</code> function calls <code>Haptics.notificationAsync(Haptics.NotificationFeedbackType.Success)</code>. This gives a short success vibration on supported devices.</p>
<p>You might expect to wrap this call in a platform check because browsers don't have the same haptics support as native apps. In this case, <code>expo-haptics</code> already includes a web implementation that uses <code>navigator.vibrate</code>, with a fallback for iOS Safari. If the browser can't provide haptics, the call simply does nothing, so we don't need an extra platform check.</p>
<p><code>notificationAsync</code> is meant for outcomes such as success or failure. <code>impactAsync</code> is for physical collisions, and <code>selectionAsync</code> is for moving through a list of options. Using the wrong one won't cause an error, but it feels slightly off.</p>
<h3 id="heading-the-full-screen">The Full Screen</h3>
<p>Now we can bring everything together in the main screen. This is where we'll keep the state, calculate the bill using <code>billFor</code>, and pass the required values and callbacks to each component.</p>
<p>When an order is placed, it sets <code>orderNumber</code>, and the screen shows a confirmation instead. Inside that confirmation, <code>&lt;Stack.Screen options&gt;</code> changes the header title to "Order sent" without navigating anywhere, so the whole flow stays in one file and one route.</p>
<p>Replace <code>app/index.tsx</code> with:</p>
<pre><code class="language-tsx">import { Bill } from '@/components/cart/bill';
import { CheckoutBar } from '@/components/cart/checkout-bar';
import { OrderRow } from '@/components/cart/order-row';
import { PickupCard } from '@/components/cart/pickup-card';
import { Button } from '@/components/ui/button';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
import { Icon } from '@/components/ui/icon';
import { Separator } from '@/components/ui/separator';
import { Text } from '@/components/ui/text';
import { billFor, INITIAL_CART, PICKUP_TIMES, type CartItem } from '@/lib/menu';
import { Stack } from 'expo-router';
import { CircleCheckIcon, MoonStarIcon, SunIcon } from 'lucide-react-native';
import * as React from 'react';
import { ScrollView, View } from 'react-native';
import { Uniwind, useUniwind } from 'uniwind';

const SCREEN_OPTIONS = {
  title: 'Your order',
  headerRight: () =&gt; &lt;ThemeToggle /&gt;,
};

export default function CartScreen() {
  const [items, setItems] = React.useState&lt;CartItem[]&gt;(INITIAL_CART);
  const [pickupValue, setPickupValue] = React.useState(PICKUP_TIMES[0].value);
  const [name, setName] = React.useState('');
  const [ownCup, setOwnCup] = React.useState(false);
  const [orderNumber, setOrderNumber] = React.useState&lt;string | null&gt;(null);

  const bill = billFor(items, ownCup);
  const itemCount = items.reduce((count, item) =&gt; count + item.qty, 0);
  const pickupLabel =
    PICKUP_TIMES.find((time) =&gt; time.value === pickupValue)?.label ?? PICKUP_TIMES[0].label;

  function changeQty(id: string, qty: number) {
    setItems((current) =&gt;
      qty &lt;= 0
        ? current.filter((item) =&gt; item.id !== id)
        : current.map((item) =&gt; (item.id === id ? { ...item, qty } : item))
    );
  }

  function placeOrder() {
    setOrderNumber(`A-${Math.floor(Math.random() * 90 + 10)}`);
  }

  function startOver() {
    setItems(INITIAL_CART);
    setOwnCup(false);
    setName('');
    setPickupValue(PICKUP_TIMES[0].value);
    setOrderNumber(null);
  }

  if (orderNumber) {
    return (
      &lt;&gt;
        &lt;Stack.Screen options={{ ...SCREEN_OPTIONS, title: 'Order sent' }} /&gt;
        &lt;View className="bg-background flex-1 items-center justify-center gap-6 p-8"&gt;
          &lt;Icon as={CircleCheckIcon} className="text-primary size-16" /&gt;
          &lt;View className="gap-2"&gt;
            &lt;Text variant="h3" className="text-center"&gt;
              We are on it
            &lt;/Text&gt;
            &lt;Text variant="muted" className="text-center"&gt;
              {`Order ${orderNumber} for ${name.trim() || 'pickup'}. Come to the far end of the counter and look for your name on the cup.`}
            &lt;/Text&gt;
          &lt;/View&gt;
          &lt;Button variant="outline" onPress={startOver}&gt;
            &lt;Text&gt;Start another order&lt;/Text&gt;
          &lt;/Button&gt;
        &lt;/View&gt;
      &lt;/&gt;
    );
  }

  return (
    &lt;&gt;
      &lt;Stack.Screen options={SCREEN_OPTIONS} /&gt;
      &lt;View className="bg-background flex-1"&gt;
        &lt;ScrollView
          className="flex-1"
          contentContainerClassName="gap-4 p-4 pb-8"
          keyboardShouldPersistTaps="handled"
          automaticallyAdjustKeyboardInsets&gt;
          &lt;Card className="gap-3 py-4"&gt;
            &lt;CardHeader className="px-4"&gt;
              &lt;CardTitle&gt;Fernwood Coffee&lt;/CardTitle&gt;
              &lt;CardDescription&gt;112 Marine Drive, counter pickup&lt;/CardDescription&gt;
            &lt;/CardHeader&gt;
            &lt;CardContent className="gap-4 px-4"&gt;
              {items.length === 0 ? (
                &lt;Text variant="muted"&gt;Your cart is empty. Add something warm.&lt;/Text&gt;
              ) : null}
              {items.map((item, index) =&gt; (
                &lt;React.Fragment key={item.id}&gt;
                  {index &gt; 0 ? &lt;Separator /&gt; : null}
                  &lt;OrderRow item={item} onChangeQty={changeQty} /&gt;
                &lt;/React.Fragment&gt;
              ))}
            &lt;/CardContent&gt;
          &lt;/Card&gt;

          &lt;Card className="gap-3 py-4"&gt;
            &lt;CardHeader className="px-4"&gt;
              &lt;CardTitle&gt;Pickup&lt;/CardTitle&gt;
            &lt;/CardHeader&gt;
            &lt;CardContent className="px-4"&gt;
              &lt;PickupCard
                pickupValue={pickupValue}
                onPickupValueChange={setPickupValue}
                name={name}
                onNameChange={setName}
                ownCup={ownCup}
                onOwnCupChange={setOwnCup}
              /&gt;
            &lt;/CardContent&gt;
          &lt;/Card&gt;

          &lt;Card className="gap-3 py-4"&gt;
            &lt;CardHeader className="px-4"&gt;
              &lt;CardTitle&gt;Bill&lt;/CardTitle&gt;
            &lt;/CardHeader&gt;
            &lt;CardContent className="px-4"&gt;
              &lt;Bill {...bill} /&gt;
            &lt;/CardContent&gt;
          &lt;/Card&gt;
        &lt;/ScrollView&gt;

        &lt;CheckoutBar
          total={bill.total}
          itemCount={itemCount}
          pickupLabel={pickupLabel}
          name={name}
          onConfirm={placeOrder}
        /&gt;
      &lt;/View&gt;
    &lt;/&gt;
  );
}

const THEME_ICONS = {
  light: SunIcon,
  dark: MoonStarIcon,
};

function ThemeToggle() {
  const { theme } = useUniwind();

  return (
    &lt;Button
      onPressIn={() =&gt; Uniwind.setTheme(theme === 'dark' ? 'light' : 'dark')}
      size="icon"
      variant="ghost"
      className="ios:size-9 web:mx-4 rounded-full"
      accessibilityLabel="Switch theme"&gt;
      &lt;Icon as={THEME_ICONS[theme ?? 'light']} className="size-5" /&gt;
    &lt;/Button&gt;
  );
}
</code></pre>
<p>Notice that <code>pickupLabel</code> is the fix from Step 7 in use. The screen looks up the label from <code>PICKUP_TIMES</code> and passes a plain string to <code>CheckoutBar</code>, so <code>CheckoutBar</code> never touches an <code>Option</code> object or the incorrect web label.</p>
<p>To test it, place an order. The dialog should show your name and the pickup time you chose (such as "in 30 minutes"), not the raw value <code>30</code>. Confirm the order, and you should see the confirmation screen:</p>
<img src="https://cdn.hashnode.com/uploads/covers/5e0f2c2e490269cb30227a2b/36e526dd-72aa-4ed6-84f0-ae16abf720a2.png" alt="The order sent screen" style="display: block;" width="414" height="896" loading="lazy">

<p>Tap "Start another order" and the cart returns to its original state.</p>
<p>The checkout screen is now working, and each part is kept in its own component. You can use the same approach when you build other screens: keep the component focused, pass the data it needs through props, and let the shared theme handle the styling.</p>
<h2 id="heading-step-11-add-dark-mode">Step 11: Add Dark Mode</h2>
<p>We already added the theme toggle in Step 10. Here's the component again so we can look at how it switches between light and dark mode:</p>
<pre><code class="language-tsx">import { Uniwind, useUniwind } from 'uniwind';

function ThemeToggle() {
  const { theme } = useUniwind();

  return (
    &lt;Button
      onPressIn={() =&gt; Uniwind.setTheme(theme === 'dark' ? 'light' : 'dark')}
      size="icon"
      variant="ghost"
      className="ios:size-9 web:mx-4 rounded-full"
      accessibilityLabel="Switch theme"&gt;
      &lt;Icon as={THEME_ICONS[theme ?? 'light']} className="size-5" /&gt;
    &lt;/Button&gt;
  );
}
</code></pre>
<p><code>Uniwind.setTheme</code> changes the values behind every token, so everything that uses <code>bg-card</code>, <code>text-muted-foreground</code>, and similar classes updates at once. <code>useUniwind</code> subscribes the component to the current theme, so the icon changes too.</p>
<p>This code also uses the <code>ios:</code> and <code>web:</code> prefixes. Uniwind supports platform variants, so <code>web:mx-4</code> only adds margin in the browser, and <code>ios:size-9</code> only applies on iOS. It's similar to <code>Platform.select</code>, but it stays inside the class string.</p>
<p>Three things aren't handled by <code>setTheme</code>, and if you forget them, you end up with a screen that's only partly dark. The template already sets up the first two.</p>
<h3 id="heading-1-the-navigation-header">1. The Navigation Header</h3>
<p>React Navigation takes its colors from a plain object, so the root layout needs to pass it the right one:</p>
<pre><code class="language-tsx">const { theme } = useUniwind();

&lt;ThemeProvider value={NAV_THEME[theme ?? 'light']}&gt;
</code></pre>
<h3 id="heading-2-the-status-bar">2. The Status Bar</h3>
<p>The clock and battery icons are drawn by the operating system, so you need to tell it which style to use. Without this, you can get dark text on a dark bar.</p>
<pre><code class="language-tsx">&lt;StatusBar style={theme === 'dark' ? 'light' : 'dark'} /&gt;
</code></pre>
<h3 id="heading-3-saving-the-choice">3. Saving the Choice</h3>
<p><code>Uniwind.setTheme</code> only applies to the current session. The next time the app starts, it follows the system setting again. To keep the user's choice, save it with <code>expo-secure-store</code> or <code>AsyncStorage</code> and call <code>setTheme</code> when the app starts. You can call <code>setTheme('system')</code> to go back to following the operating system.</p>
<p>When you tap the header icon, the cards, borders, inputs, switch, header, and status bar should all change together. You can explore more ready-made <a href="https://shadcnstudio.com/blocks">shadcn blocks</a> if you want examples of how these components are used in larger interfaces:</p>
<img src="https://cdn.hashnode.com/uploads/covers/5e0f2c2e490269cb30227a2b/4e54a370-5335-42fe-95df-8eee7b033e78.png" alt="The screen in dark mode" style="display: block;" width="414" height="896" loading="lazy">

<p>Look for anything that stays light while the rest goes dark. A light header usually means the <code>ThemeProvider</code> is not receiving the new <code>NAV_THEME</code>.</p>
<h2 id="heading-step-12-create-your-own-theme">Step 12: Create Your Own Theme</h2>
<p>The screen is currently using the default gray theme. Let's change it to a coffee-inspired palette with warm cream backgrounds and brown accents. This will also help us see why the palette needs to be updated in both <code>global.css</code> and <code>lib/theme.ts</code>.</p>
<h3 id="heading-update-the-tokens">Update the Tokens</h3>
<p>Replace the <code>@layer theme</code> block in <code>global.css</code> with this coffee palette:</p>
<pre><code class="language-css">@layer theme {
  :root {
    @variant light {
      --color-background: oklch(0.98 0.008 75);
      --color-foreground: oklch(0.24 0.02 60);
      --color-card: oklch(1 0.003 90);
      --color-card-foreground: oklch(0.24 0.02 60);
      --color-popover: oklch(1 0.003 90);
      --color-popover-foreground: oklch(0.24 0.02 60);
      --color-primary: oklch(0.44 0.06 45);
      --color-primary-foreground: oklch(0.99 0.01 85);
      --color-secondary: oklch(0.93 0.03 80);
      --color-secondary-foreground: oklch(0.35 0.05 45);
      --color-muted: oklch(0.95 0.012 80);
      --color-muted-foreground: oklch(0.52 0.02 60);
      --color-accent: oklch(0.92 0.04 78);
      --color-accent-foreground: oklch(0.32 0.05 45);
      --color-destructive: oklch(0.577 0.245 27.325);
      --color-border: oklch(0.89 0.02 75);
      --color-input: oklch(0.89 0.02 75);
      --color-ring: oklch(0.44 0.06 45);
    }

    @variant dark {
      --color-background: oklch(0.17 0.012 60);
      --color-foreground: oklch(0.96 0.008 85);
      --color-card: oklch(0.22 0.016 62);
      --color-card-foreground: oklch(0.96 0.008 85);
      --color-popover: oklch(0.22 0.016 62);
      --color-popover-foreground: oklch(0.96 0.008 85);
      --color-primary: oklch(0.85 0.09 75);
      --color-primary-foreground: oklch(0.22 0.03 55);
      --color-secondary: oklch(0.29 0.022 62);
      --color-secondary-foreground: oklch(0.94 0.01 85);
      --color-muted: oklch(0.27 0.018 62);
      --color-muted-foreground: oklch(0.72 0.015 75);
      --color-accent: oklch(0.31 0.03 65);
      --color-accent-foreground: oklch(0.95 0.01 85);
      --color-destructive: oklch(0.704 0.191 22.216);
      --color-border: oklch(1 0 0 / 12%);
      --color-input: oklch(1 0 0 / 15%);
      --color-ring: oklch(0.85 0.09 75);
    }
  }
}
</code></pre>
<p>If you don't want to choose thirty colors by hand, you can generate a theme with the <a href="https://shadcnstudio.com/theme-generator">shadcn theme generator</a> or <a href="https://tweakcn.com/">tweakcn</a>. Both export CSS variables, but you need to make two changes before the output works in this project:</p>
<ol>
<li>Rename each variable to include the <code>--color-</code> prefix. For example, <code>--primary</code> becomes <code>--color-primary</code>.</li>
<li>Move the <code>:root</code> block inside <code>@variant light</code>, and the <code>.dark</code> block inside <code>@variant dark</code>.</li>
</ol>
<p>Also remove <code>--radius</code> from what you paste, because the template already defines it along with the derived sizes. Remove any <code>--shadow-*</code> variables too, since nothing in the registry reads them.</p>
<h3 id="heading-update-libthemets">Update lib/theme.ts</h3>
<p>After you save and reload, the result looks like this:</p>
<img src="https://cdn.hashnode.com/uploads/covers/5e0f2c2e490269cb30227a2b/eb94958b-f7d3-4d64-9703-2b9153e4ea6f.png" alt="The new theme with a white header" style="display: block;" width="414" height="896" loading="lazy">

<p>The page is cream, the button is brown, and the badges have the right color, but the header is still white with a visible line under it. The reason is that React Navigation draws the header using <code>lib/theme.ts</code>, and that file still has the old palette. Nothing is broken and nothing warns you, so this mistake is easy to miss. If you're designing the same interface in Figma, the <a href="https://shadcnstudio.com/figma">shadcn Figma resources</a> can also help you keep the design and implementation aligned.</p>
<p>Update <code>lib/theme.ts</code> to match:</p>
<pre><code class="language-tsx">import { DarkTheme, DefaultTheme, type Theme } from 'expo-router/react-navigation';

export const THEME = {
  light: {
    background: '#fcf8f3',
    foreground: '#261d16',
    card: '#fffffd',
    primary: '#6e4836',
    border: '#e3d9cd',
    destructive: '#e7000b',
    /* the rest of the list */
  },
  dark: {
    background: '#130e0a',
    foreground: '#f4f1ec',
    card: '#201913',
    primary: '#f1c68b',
    border: '#3a3129',
    destructive: '#ff6467',
    /* the rest of the list */
  },
};

export const NAV_THEME: Record&lt;'light' | 'dark', Theme&gt; = {
  light: {
    ...DefaultTheme,
    colors: {
      background: THEME.light.background,
      border: THEME.light.border,
      card: THEME.light.background,
      notification: THEME.light.destructive,
      primary: THEME.light.primary,
      text: THEME.light.foreground,
    },
  },
  dark: {
    ...DarkTheme,
    colors: {
      background: THEME.dark.background,
      border: THEME.dark.border,
      card: THEME.dark.background,
      notification: THEME.dark.destructive,
      primary: THEME.dark.primary,
      text: THEME.dark.foreground,
    },
  },
};
</code></pre>
<p>This isn't a direct copy of <code>global.css</code>, so three points need explanation:</p>
<ul>
<li><strong>Use hex colors instead of</strong> <code>oklch()</code><strong>:</strong> Uniwind converts <code>oklch()</code> for your classes, but React Navigation does not, so give it a format that React Native can read directly. You can convert a color with any online converter, or paste the <code>oklch()</code> value into your browser's developer tools color picker and read the hex value.</li>
<li><strong>Map React Navigation's</strong> <code>card</code> <strong>to your</strong> <code>background</code><strong>, not your</strong> <code>card</code><strong>.</strong> The two names look the same but mean different things. In shadcn, <code>card</code> is a raised surface on top of the page. In React Navigation, <code>card</code> is the background of the screen and header. If you map them by name, the header ends up a shade lighter than the page. You won't notice this with the stock template because it uses the same value for <code>card</code> and <code>background</code>. It only shows up once you create a theme where cards stand out from the page, like this one.</li>
<li><strong>Use a solid color in place of a transparent border.</strong> In dark mode, <code>--color-border</code> is <code>oklch(1 0 0 / 12%)</code>, which is white at 12% opacity. A navigation theme needs a solid color, so work out what that border looks like on your background and use that value.</li>
</ul>
<p>After this change, the header and page match in both light and dark mode, and you didn't edit any component files:</p>
<img src="https://cdn.hashnode.com/uploads/covers/5e0f2c2e490269cb30227a2b/f24b38ac-9742-44d3-92d6-2061477bc314.png" alt="The final theme with a matching header" style="display: block;" width="414" height="896" loading="lazy">

<img src="https://cdn.hashnode.com/uploads/covers/5e0f2c2e490269cb30227a2b/8627fc51-5083-4f8f-bae4-370f860b389e.png" alt="The final theme in the other mode" style="display: block;" width="414" height="896" loading="lazy">

<p>Switch between light and dark a few times and watch the header. If it's a shade lighter or darker than the page, one of the values in <code>lib/theme.ts</code> is still from the old palette.</p>
<h2 id="heading-common-mistakes-and-how-to-fix-them">Common Mistakes and How to Fix Them</h2>
<p>If you're coming from web development, some of these differences may catch you off guard. I've collected the issues covered in the tutorial in the table below, along with the fix for each one. You can refer back to it when something doesn't behave as expected.</p>
<table>
<thead>
<tr>
<th>What you do</th>
<th>What happens</th>
<th>The fix</th>
</tr>
</thead>
<tbody><tr>
<td><code>&lt;Badge&gt;Medium&lt;/Badge&gt;</code></td>
<td>Red screen: "Text strings must be rendered within a <code>&lt;Text&gt;</code>."</td>
<td>Wrap the text: <code>&lt;Badge&gt;&lt;Text&gt;Medium&lt;/Text&gt;&lt;/Badge&gt;</code>. The same applies to <code>Button</code>.</td>
</tr>
<tr>
<td><code>{count &amp;&amp; &lt;Line/&gt;}</code> when <code>count</code> is <code>0</code></td>
<td>The same error, caused by a stray <code>0</code></td>
<td><code>{count &gt; 0 ? &lt;Line/&gt; : null}</code></td>
</tr>
<tr>
<td><code>space-y-3</code> on a column</td>
<td>Nothing happens and there is no warning</td>
<td>Use <code>gap-3</code> on the parent</td>
</tr>
<tr>
<td><code>className="p-4"</code> on a <code>ScrollView</code></td>
<td>Padding is clipped and gaps are ignored</td>
<td>Use <code>contentContainerClassName</code></td>
</tr>
<tr>
<td><code>truncate</code> on a long name</td>
<td>The text isn't truncated and the price is pushed off screen</td>
<td>Use <code>numberOfLines={1}</code></td>
</tr>
<tr>
<td>Using <code>flex</code> and expecting a row</td>
<td>Items stack vertically</td>
<td>React Native defaults to a column, so add <code>flex-row</code></td>
</tr>
<tr>
<td><code>hover:bg-accent</code></td>
<td>Nothing happens on a device</td>
<td>Use <code>active:</code> for the pressed state</td>
</tr>
<tr>
<td>Deleting <code>PortalHost</code> from the layout</td>
<td>Dropdowns open into nothing, with no error</td>
<td>Put it back</td>
</tr>
<tr>
<td>A Select near the bottom of the screen</td>
<td>The last option is under the home indicator</td>
<td>Pass <code>insets</code> to <code>SelectContent</code></td>
</tr>
<tr>
<td>Showing <code>option.label</code> from <code>onValueChange</code></td>
<td>Correct on native, but the raw value on the web</td>
<td>Look up the label from your own data</td>
</tr>
<tr>
<td>A bottom bar with only <code>p-4</code></td>
<td>The button is under the gesture bar</td>
<td>Use <code>paddingBottom: insets.bottom + 12</code> in <code>style</code></td>
</tr>
<tr>
<td>28-point stepper buttons</td>
<td>Hard to tap with a thumb</td>
<td>Add <code>hitSlop={8}</code></td>
</tr>
<tr>
<td>Changing only <code>global.css</code> for a new theme</td>
<td>The header keeps the old colors</td>
<td>Update <code>lib/theme.ts</code> too</td>
</tr>
<tr>
<td><code>&lt;Avatar&gt;</code> without <code>alt</code></td>
<td>TypeScript won't compile</td>
<td><code>alt</code> is required, and it becomes the accessibility label</td>
</tr>
<tr>
<td><code>rounded-2xl</code> on <code>Avatar</code> only</td>
<td>A circular fallback inside rounded corners</td>
<td>Repeat it on <code>AvatarFallback</code></td>
</tr>
<tr>
<td>Guarding haptics with <code>Platform.OS !== 'web'</code></td>
<td>A working web fallback is removed</td>
<td><code>expo-haptics</code> already handles the web</td>
</tr>
<tr>
<td>Right-aligned prices in a normal font</td>
<td>Digits shift whenever the number changes</td>
<td>Use <code>tabular-nums</code>, which also works on native</td>
</tr>
<tr>
<td><code>&lt;Separator className="h-hairline" /&gt;</code></td>
<td>Both height classes are kept</td>
<td>See below</td>
</tr>
</tbody></table>
<p>The last row needs more explanation, because it looks like a bug in <code>cn()</code>, but it's not.</p>
<p><code>cn()</code> uses <code>tailwind-merge</code>, which resolves conflicts between classes. It knows the default Tailwind scale, but it doesn't know about custom values you declare in <code>global.css</code>. The value <code>hairline</code> comes from <code>--spacing-hairline: hairlineWidth()</code>, so <code>tailwind-merge</code> can't tell that <code>h-hairline</code> and <code>h-[1px]</code> set the same property, and it keeps both:</p>
<pre><code class="language-jsx">cn('h-[1px] w-full', 'h-hairline my-1')  // 'h-[1px] w-full h-hairline my-1'
cn('h-[1px] w-full', 'h-2 my-1')         // 'w-full h-2 my-1'
</code></pre>
<p>The second result is correct. In the first, which height wins depends on the order of the CSS. The other overrides in this tutorial, such as <code>size-14</code> over <code>size-8</code>, work correctly because those are names <code>tailwind-merge</code> recognizes. If you want it to understand your custom scale, you can teach it with <code>extendTailwindMerge</code> in <code>lib/utils.ts</code>. Otherwise, use an arbitrary value, or edit the component file directly, since you own it.</p>
<p>There's a related case in the stepper buttons. They pass <code>size-7</code> to a <code>Button</code> whose icon size is <code>h-10 w-10 sm:h-9 sm:w-9</code>:</p>
<pre><code class="language-jsx">cn('h-10 w-10 sm:h-9 sm:w-9', 'size-7 rounded-full')
// 'sm:h-9 sm:w-9 size-7 rounded-full'
</code></pre>
<p><code>size-7</code> replaces the base <code>h-10 w-10</code>, but the two <code>sm:</code> classes stay, because <code>tailwind-merge</code> treats a responsive variant as a different class. On a phone this makes no difference, since <code>sm:</code> starts at 640px and phones are narrower than that. In a desktop browser, though, those buttons grow to 36 points.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>In this tutorial, we built a coffee shop cart and checkout screen with React Native Reusables, Expo, and Uniwind. We added the order rows, pickup options, bill summary, fixed checkout bar, and confirmation dialog. We also looked at how the registry and CLI add component source code to the project and how the theme tokens control the app's colors.</p>
<p>One thing worth getting into the habit of is checking the component source when something doesn't behave the way you expect. Since the components live in your project, you can open them and see how they work. That's how we understood the difference in the Select label between web and native. It also makes customization easier because you can see which part of the component needs to change instead of adding more workarounds around it.</p>
<p>You can find the complete project in the <a href="https://github.com/shadcnstudio/shadcn-react-native-app">GitHub repository</a>. If you run into an issue or want to compare your code with the finished screen, clone the repository and check the implementation. If you're looking for more complete starting points for your next project, take a look at <a href="https://shadcnstudio.com/templates">shadcn templates</a>.</p>
<p>I captured the screenshots using the React Native Web build at a phone-sized viewport. The same project also runs on iOS and Android. I've called out the platform differences in the relevant sections, including the Select label and portal host in Step 7, safe area handling in Step 9, and haptics in Step 10.</p>
<h3 id="heading-resources">Resources</h3>
<p><strong>React Native Reusables</strong></p>
<ul>
<li><a href="https://reactnativereusables.com/">reactnativereusables.com</a>: documentation and the registry</li>
<li><a href="https://reactnativereusables.com/docs">Introduction</a>: the list of differences from web shadcn</li>
<li><a href="https://reactnativereusables.com/docs/cli">CLI reference</a>: the <code>init</code>, <code>add</code>, and <code>doctor</code> commands</li>
<li><a href="https://reactnativereusables.com/docs/create-your-own-registry">Create your own registry</a>: publish components your team can add with the CLI</li>
<li><a href="https://github.com/founded-labs/react-native-reusables">The repository</a>: MIT licensed</li>
<li>Any registry entry is a public URL: <code>reactnativereusables.com/r/uniwind/&lt;name&gt;.json</code> or <code>.../r/nativewind/&lt;name&gt;.json</code></li>
</ul>
<p><strong>Tools used</strong></p>
<ul>
<li><a href="https://rnprimitives.com/">RN Primitives</a></li>
<li><a href="https://docs.uniwind.dev/">Uniwind</a></li>
<li><a href="https://www.nativewind.dev/">Nativewind</a></li>
<li><a href="https://docs.expo.dev/router/introduction/">Expo Router</a></li>
<li><a href="https://ui.shadcn.com/">shadcn/ui</a> and the <a href="https://ui.shadcn.com/docs/registry">registry specification</a></li>
</ul>
<p><strong>APIs used</strong></p>
<ul>
<li><a href="https://github.com/appandflow/react-native-safe-area-context"><code>useSafeAreaInsets</code></a></li>
<li><a href="https://docs.expo.dev/versions/latest/sdk/haptics/"><code>expo-haptics</code></a></li>
<li><a href="https://reactnative.dev/docs/view#hitslop"><code>hitSlop</code></a></li>
<li><a href="https://reactnative.dev/docs/text#numberoflines"><code>numberOfLines</code></a></li>
<li><a href="https://github.com/dcastil/tailwind-merge"><code>tailwind-merge</code></a></li>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/color_value/oklch"><code>oklch()</code></a></li>
</ul>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Use Flex in Tailwind CSS and Justify Flex Items ]]>
                </title>
                <description>
                    <![CDATA[ Hey there! If you're building modern web interfaces, chances are you've already fallen in love with Tailwind CSS for its speed and flexibility. One of the most powerful tools in Tailwind's arsenal is  ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-use-flex-in-tailwind-css-and-justify-flex-items/</link>
                <guid isPermaLink="false">69b1975b6c896b0519a78b21</guid>
                
                    <category>
                        <![CDATA[ flexbox ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Tailwind CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Tailwind CSS Tutorial ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tailwind ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Flex ]]>
                    </category>
                
                    <category>
                        <![CDATA[ flex css ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Ajay Patel ]]>
                </dc:creator>
                <pubDate>Wed, 11 Mar 2026 16:24:59 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/uploads/covers/5e1e335a7a1d3fcc59028c64/3522007b-55f0-44bf-9b6f-b0489d1a8774.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Hey there! If you're building modern web interfaces, chances are you've already fallen in love with Tailwind CSS for its speed and flexibility.</p>
<p>One of the most powerful tools in Tailwind's arsenal is its set of Flexbox utilities. Flexbox lets you create dynamic, responsive layouts without writing custom CSS, and Tailwind makes it incredibly intuitive with simple class names.</p>
<p>In this tutorial, we'll walk through everything you need to know about using Flexbox in Tailwind, from the basics to advanced patterns. Whether you're a beginner or looking to level up your layouts, by the end, you'll feel confident building anything from card grids to complex dashboards.</p>
<h2 id="heading-table-of-contents">Table of Contents</h2>
<ul>
<li><p><a href="https://preview.freecodecamp.org/69857b45ac030cc5d597ac21#heading-prerequisites">Prerequisites</a></p>
</li>
<li><p><a href="#heading-what-is-flexbox">What is Flexbox?</a></p>
</li>
<li><p><a href="#heading-how-tailwind-css-makes-flexbox-easy-to-use">How Tailwind CSS Makes Flexbox Easy to Use</a></p>
</li>
<li><p><a href="#heading-how-to-use-flex-in-tailwind">How to use flex in Tailwind</a></p>
</li>
<li><p><a href="#heading-flex-item-sizing-basis-grow-amp-shrink">Flex Item Sizing: Basis, Grow &amp; Shrink</a></p>
</li>
<li><p><a href="#heading-controlling-flex-direction">Controlling Flex Direction</a></p>
</li>
<li><p><a href="#heading-fine-tuning-flexbox-layout">Fine-Tuning Flexbox Layout</a></p>
</li>
<li><p><a href="#heading-how-to-justify-and-align-flex-items-in-tailwind">How to Justify and Align Flex Items in Tailwind</a></p>
</li>
<li><p><a href="#heading-practice-flexbox-with-interactive-games">Practice Flexbox with Interactive Games</a></p>
</li>
<li><p><a href="#heading-conclusion">Conclusion:</a></p>
</li>
</ul>
<h2 id="heading-prerequisites"><strong>Prerequisites</strong></h2>
<p>Before diving into Flexbox with Tailwind CSS, it helps to have a few basics in place so you can follow along comfortably.</p>
<p><strong>Basic Knowledge:</strong></p>
<ul>
<li><p>A foundational understanding of <strong>HTML</strong> (how elements and containers work).</p>
</li>
<li><p>Basic familiarity with <strong>CSS</strong> (especially properties like <code>display</code>, <code>width</code>, and <code>height</code>).</p>
</li>
<li><p>A general idea of how responsive design works (helpful but not required).</p>
</li>
</ul>
<p>You do <em>not</em> need to be a Flexbox expert, as we’ll cover the important concepts as we go.</p>
<p><strong>Tools You’ll Need:</strong></p>
<ul>
<li><p>A code editor like VS Code (or any editor you prefer)</p>
</li>
<li><p>A browser for testing layouts</p>
</li>
<li><p>A project with Tailwind CSS installed</p>
</li>
</ul>
<h2 id="heading-what-is-flexbox">What is Flexbox?</h2>
<p><strong>Flexbox (Flexible Box Layout)</strong> is a CSS layout model designed to make it easier to design flexible, responsive layouts without using floats or complicated positioning tricks.</p>
<p>Before Flexbox, aligning elements vertically, spacing items evenly, or making layouts adapt to different screen sizes was often frustrating and required hacks. Flexbox solves these problems by providing a simple and predictable way to control alignment, spacing, and ordering of elements inside a container.</p>
<p>The main concept is simple:</p>
<ul>
<li><p>You have a flex container</p>
</li>
<li><p>Inside it are flex items</p>
</li>
<li><p>The container controls how its items are laid out</p>
</li>
</ul>
<p>Once an element is set to <code>display: flex</code>, its children automatically become flex items.</p>
<pre><code class="language-css">.container {
  display: flex;
}
</code></pre>
<h2 id="heading-how-tailwind-css-makes-flexbox-easy-to-use">How Tailwind CSS Makes Flexbox Easy to Use</h2>
<p>Flexbox is powerful, but writing custom CSS for every layout can become repetitive and time-consuming. Tailwind CSS simplifies this by providing utility classes that map directly to Flexbox properties, allowing developers to build layouts quickly without writing custom CSS.</p>
<p>Instead of switching between HTML and CSS files, Tailwind lets you apply Flexbox behavior directly in your markup, making layouts more readable and faster to develop. It turns Flexbox's sometimes verbose properties into short, memorable utilities. No more remembering <code>justify-content: space-between;</code> just write <code>justify-between</code>.</p>
<p>Benefits:</p>
<ul>
<li><p>Responsive by default (add <code>md:</code>, <code>lg:</code>, and so on)</p>
</li>
<li><p>Composable (combine classes freely).</p>
</li>
<li><p>No custom CSS needed for most cases.</p>
</li>
</ul>
<h2 id="heading-how-to-use-flex-in-tailwind">How to Use Flex in Tailwind</h2>
<p>Flexbox is one of the most powerful layout systems in modern CSS, and Tailwind CSS makes it extremely approachable by exposing Flexbox behavior through simple utility classes. Instead of writing custom CSS, you compose layouts directly in your HTML using predefined classes.</p>
<ol>
<li><p><code>flex</code>: The <code>flex</code> Class is the foundation of Flexbox in Tailwind.</p>
</li>
<li><p><code>flex-1</code>: Allows the element to grow and shrink and forces it to take up the remaining available space.</p>
</li>
<li><p><code>flex-auto</code>: It makes an item flexible while respecting its content size – that is, it only grows and shrinks as needed.</p>
</li>
<li><p><code>flex-none</code>: Disables growing and shrinking for an item.</p>
</li>
</ol>
<p>Here is a basic example that shows where to place these classes:</p>
<pre><code class="language-xml">&lt;!-- this is the container --&gt;
&lt;div class="flex"&gt;
  &lt;!-- these are the items inside the container --&gt;
  &lt;div class="flex-1"&gt;Item 1&lt;/div&gt;
  &lt;div class="flex-auto"&gt;Item 2&lt;/div&gt;
  &lt;div class="flex-none"&gt;Item 3&lt;/div&gt;
&lt;/div&gt;
</code></pre>
<h2 id="heading-flex-item-sizing-basis-grow-amp-shrink">Flex Item Sizing: Basis, Grow, &amp; Shrink</h2>
<p>Three fundamental properties control how elements size themselves inside a flex container:</p>
<ul>
<li><p>flex-basis</p>
</li>
<li><p>flex-grow</p>
</li>
<li><p>flex-shrink</p>
</li>
</ul>
<p>Rather than thinking in fixed widths and heights, Flexbox uses a dynamic space-distribution model. Each flex item starts with an initial size, then grows or shrinks depending on the available space and the rules defined by these three properties.</p>
<h3 id="heading-flex-basis">flex-basis</h3>
<p><a href="https://tailwindcss.com/docs/flex-basis">flex-basis</a> controls the initial size of a flex item before <code>flex-grow</code> or <code>flex-shrink</code> kick in. Think of it as the item’s starting width or height (depending on flex direction).</p>
<pre><code class="language-xml">&lt;div class="flex ..."&gt;
	&lt;div class="... basis-1/5"&gt;01&lt;/div&gt;
  &lt;div class="...basis-4/5"&gt;02&lt;/div&gt;
&lt;/div&gt;
</code></pre>
<p>Here's what this makes:</p>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1770355749158/19071bac-8426-4602-a7ab-fcc0ecd62c95.png" alt="flex basis" style="display: block;" width="553" height="94" loading="lazy">

<p>flex-basis's most used utility classes are:</p>
<ul>
<li><p><code>basis-auto</code>: This means the item’s initial size is based on its <strong>content size or any explicitly defined width/height</strong>. It doesn't force a specific starting size. Instead, it respects intrinsic sizing.</p>
</li>
<li><p><code>basis-0</code>: This makes the item start at <strong>0 width (or height in column layouts)</strong> before space is distributed. It’s commonly used with <code>grow</code> to evenly distribute space regardless of content size.</p>
</li>
<li><p><code>basis-full</code>: The item initially takes up the <strong>entire width (or height)</strong> of the container before shrinking or wrapping.</p>
</li>
<li><p><code>basis-xs/md/lg/xl..</code>: Built-in values.</p>
</li>
<li><p><code>basis-&lt;fraction&gt;</code>: Giving a value with a dynamic such as 1/2, 4/5, and so on.</p>
</li>
<li><p><code>basis-&lt;number&gt;</code>: Uses Tailwind’s spacing scale (in <code>rem</code> units).</p>
</li>
<li><p><code>basis-[&lt;value&gt;]</code>: Syntax to set the basis based on a completely custom value.</p>
</li>
</ul>
<h3 id="heading-flex-grow">flex-grow</h3>
<p><a href="https://tailwindcss.com/docs/flex-grow">flex-grow</a> controls how much a flex item expands to fill extra space in the flex container. It determines how leftover space is distributed among flex items after their initial sizes.</p>
<pre><code class="language-xml">&lt;div class="flex ..."&gt;
	&lt;div class="... grow"&gt;01&lt;/div&gt;
  &lt;div class="...grow-0"&gt;02&lt;/div&gt;
  &lt;div class="...grow"&gt;03&lt;/div&gt;
&lt;/div&gt;
</code></pre>
<p>Here's what this creates:</p>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1770355790996/6c4f3c72-0ff9-4f5c-bab7-6e5bc1e9df2e.png" alt="flex grow" style="display: block;" width="471" height="92" loading="lazy">

<p>flex-grow's most used utility classes are:</p>
<ul>
<li><p><code>grow</code>: The item will grow to take up available extra space. If multiple items use <code>grow</code>, they share space equally (unless different grow values are specified)..</p>
</li>
<li><p><code>grow-0</code>: The item will <strong>not expand</strong> beyond its initial size, even if extra space is available.</p>
</li>
<li><p><code>grow-&lt;number&gt;</code>: If one item has <code>grow-2</code> and another has <code>grow-1</code>, the first item gets <strong>twice as much extra space</strong> as the second.</p>
</li>
<li><p><code>grow-[&lt;value&gt;]</code>: Allows a custom grow value (e.g. grow-[3]).</p>
</li>
</ul>
<h3 id="heading-flex-shrink">flex-shrink</h3>
<p><a href="https://tailwindcss.com/docs/flex-shrink">flex-shrink</a> controls how much a flex item shrinks when there isn’t enough space in the flex container. It determines how items reduce their size relative to each other when the container overflows.</p>
<pre><code class="language-xml">&lt;div class="flex ..."&gt;
	&lt;div class="... grow shrink-0"&gt;01&lt;/div&gt;
  &lt;div class="...shrink"&gt;02&lt;/div&gt;
  &lt;div class="...grow shrink-0"&gt;03&lt;/div&gt;
&lt;/div&gt;
</code></pre>
<p>Here's what this creates:</p>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1770355844387/bd1b9e5c-0ae5-4e61-97f7-2cbfbc060ecf.png" alt="flex shrink" style="display: block;" width="630" height="90" loading="lazy">

<p>flex-shrink's most used utility classes are:</p>
<ul>
<li><p><code>shrink</code>: The item is allowed to shrink when necessary to prevent overflow.</p>
</li>
<li><p><code>shrink-0</code>: The item will <strong>not shrink</strong>, even if space becomes limited. This may cause overflow if other items cannot compensate.</p>
</li>
<li><p><code>shrink-&lt;number&gt;</code>: Sets proportional shrinking behavior. An item with <code>shrink-2</code> will shrink <strong>twice as much</strong> as one with <code>shrink-1</code>.</p>
</li>
<li><p><code>shrink-[&lt;value&gt;]</code>: Syntax to set a completely custom shrink value.</p>
</li>
</ul>
<h2 id="heading-controlling-flex-direction">Controlling Flex Direction</h2>
<p>In Tailwind CSS, the direction in which flex items are laid out is controlled using <a href="https://tailwindcss.com/docs/flex-direction">flex-direction utilities</a>. These utilities define whether items are placed horizontally or vertically, and in which order.</p>
<h3 id="heading-flex-row">flex-row</h3>
<p><code>flex-row</code> is the default flex direction in both CSS Flexbox and Tailwind. When it is applied, flex items are laid out <strong>horizontally</strong> along the main axis, starting from left to right (in left-to-right languages).</p>
<pre><code class="language-xml">&lt;div class="flex flex-row"&gt;
  &lt;div&gt;01&lt;/div&gt;
  &lt;div&gt;02&lt;/div&gt;
  &lt;div&gt;03&lt;/div&gt;
&lt;/div&gt;
</code></pre>
<p>This outputs:</p>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1770356616341/4b3dbd4c-e437-49d0-a9b5-0576781ccfc3.png" alt="flex row default" style="display: block;" width="285" height="141" loading="lazy">

<p><strong>Use case:</strong> Navigation bars, horizontal button groups, toolbars.</p>
<h3 id="heading-flex-row-reverse">flex-row-reverse</h3>
<p>The <code>flex-row-reverse</code> utility lays out flex items horizontally, but in the opposite direction from right to left. While the visual order of items is reversed, the HTML source order remains unchanged, which is important for accessibility and screen readers.</p>
<pre><code class="language-xml">&lt;div class="flex flex-row-reverse"&gt;
  &lt;div&gt;01&lt;/div&gt;
  &lt;div&gt;02&lt;/div&gt;
  &lt;div&gt;03&lt;/div&gt;
&lt;/div&gt;
</code></pre>
<p>Output:</p>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1770356916275/1fad634a-c4a0-4417-a63e-0ed51d9f76f7.png" alt="flex row reverse" style="display: block;" width="272" height="146" loading="lazy">

<p><strong>Use case:</strong> Forms, cards, sidebars, vertical menus.</p>
<h3 id="heading-flex-col">flex-col</h3>
<p>The <code>flex-col</code> utility changes the flex direction to <strong>vertical</strong>, stacking items from top to bottom. In this case, the main axis runs vertically.</p>
<pre><code class="language-html">&lt;div class="flex flex-col"&gt;
  &lt;div&gt;01&lt;/div&gt;
  &lt;div&gt;02&lt;/div&gt;
  &lt;div&gt;03&lt;/div&gt;
&lt;/div&gt; 
</code></pre>
<p>Output:</p>
<img src="https://cdn.hashnode.com/uploads/covers/5e0f2c2e490269cb30227a2b/cea4e846-a234-42e8-9509-2b166a5cf5c4.png" alt="cea4e846-a234-42e8-9509-2b166a5cf5c4" style="display: block;" width="282" height="312" loading="lazy">

<p><strong>Use case:</strong> Forms, cards, sidebars, vertical menus.</p>
<h3 id="heading-flex-col-reverse">flex-col-reverse</h3>
<p>In <code>flex-col-reverse</code>, items are stacked vertically, but in <strong>reverse order</strong>, starting from bottom to top (that is, vertically reverse order).</p>
<pre><code class="language-xml">&lt;div class="flex flex-col-reverse"&gt;
  &lt;div&gt;01&lt;/div&gt;
  &lt;div&gt;02&lt;/div&gt;
  &lt;div&gt;03&lt;/div&gt;
&lt;/div&gt; 
</code></pre>
<p>Here's the output:</p>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1770357355380/9d2d03b9-0c23-4360-ab82-2ccf8c1f32d9.png" alt="flex col reverse" style="display: block;" width="291" height="313" loading="lazy">

<p><strong>Use case:</strong> Chat messages, timelines, or when newer content should appear at the bottom.</p>
<p>Now you know a bit about managing flex-directions using tailwind utility classes. You can mange the stack depending on your needs.</p>
<h3 id="heading-responsive-control">Responsive Control</h3>
<p>Tailwind also allows you to change flex direction at different breakpoints so you’ll get a clean layout across different devices.</p>
<pre><code class="language-html">&lt;div class="flex flex-col md:flex-row"&gt;
	.....
&lt;/div&gt;
</code></pre>
<p>This stacks items vertically on small screens and switches to a horizontal layout on medium screens and above.</p>
<h2 id="heading-fine-tuning-flexbox-layout">Fine-Tuning Flexbox Layout</h2>
<p>Once a container is set to use Flexbox, the real power comes from controlling how flex items behave inside it. This is where properties like wrap, order, and gap become essential. These features determine how items flow, how they're visually arranged, and how much space exists between them.</p>
<p>In real-world layouts such as card grids, navigation menus, and dashboards, elements rarely fit perfectly in a single row or follow a fixed order across all screen sizes. Flexbox provides solutions to these challenges, and Tailwind CSS exposes them through simple, intuitive utility classes.</p>
<ul>
<li><p><strong>Wrap</strong> helps manage what happens when items exceed the available space</p>
</li>
<li><p><strong>Order</strong> allows you to rearrange elements visually without changing the HTML structure</p>
</li>
<li><p><strong>Gap</strong> controls spacing between items in a clean and predictable way</p>
</li>
</ul>
<p>Let’s dive into the depths of these fine-tuning flexbox properties.</p>
<h3 id="heading-flex-wrap"><a href="https://tailwindcss.com/docs/flex-wrap">flex-wrap</a></h3>
<p>By default, Flexbox tries to fit all items into one line. If there isn’t enough space, items will shrink to squeeze in. <code>flex-wrap</code> allows flex-items to move onto the next line instead of shrinking.</p>
<pre><code class="language-xml">&lt;div class="flex flex-wrap"&gt;
	&lt;div&gt;01&lt;div&gt;
	&lt;div&gt;02&lt;div&gt;
	&lt;div&gt;03&lt;div&gt;
&lt;/div&gt;
</code></pre>
<p><strong>Utility classes</strong>:</p>
<ul>
<li><p><code>flex-nowrap</code>: (default) All items stay on one line.</p>
</li>
<li><p><code>flex-wrap</code>: Items wrap onto multiple lines.</p>
</li>
<li><p><code>flex-wrap-reverse</code>: Items wrap, but in reverse order.</p>
</li>
</ul>
<h3 id="heading-flex-order">flex-order</h3>
<p><a href="https://tailwindcss.com/docs/order">flex-order</a> controls the visual order of the stack/flex-items without changing the HTML structure. Each item has an order value. Items with lower order values appear first.</p>
<pre><code class="language-xml">&lt;div class="flex"&gt;
	&lt;div class="order-3 ..."&gt;01&lt;div&gt;
	&lt;div class="order-1 ..."&gt;02&lt;div&gt;
	&lt;div class="order-2 ..."&gt;03&lt;div&gt;
&lt;/div&gt;
</code></pre>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1770357768674/b70b52ca-712e-409a-a0af-f73be8b2c649.png" alt="default order custom order" style="display: block;" width="564" height="148" loading="lazy">

<p><strong>Utility classes:</strong></p>
<ul>
<li><p><code>order-1</code> to <code>order-12</code>: Sets order value.</p>
</li>
<li><p><code>order-first</code>: Moves item to the start.</p>
</li>
<li><p><code>order-last</code>: Moves item to the end.</p>
</li>
<li><p><code>order-none</code>: Default order (0).</p>
</li>
</ul>
<h3 id="heading-gap">gap</h3>
<p><a href="https://tailwindcss.com/docs/gap">gap</a> controls the space between flex items, both rows and columns, without using margins. You can also apply for axis, which will help in giving space in both horizontal and vertical directions.</p>
<p>Here's an example of using it with a horizontal layout:</p>
<pre><code class="language-xml">&lt;div class="flex gap-8"&gt;
	&lt;div&gt;01&lt;div&gt;
	&lt;div&gt;02&lt;div&gt;
	&lt;div&gt;03&lt;div&gt;
&lt;/div&gt;
</code></pre>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1770357860338/520e4c08-e334-4bee-9003-d6b22e857a18.png" alt="gap" style="display: block;" width="551" height="139" loading="lazy">

<p>And here's an example showing a vertical layout:</p>
<pre><code class="language-xml">&lt;div class="flex flex-col gap-y-5"&gt;
	&lt;div&gt;01&lt;div&gt;
	&lt;div&gt;02&lt;div&gt;
	&lt;div&gt;03&lt;div&gt;
&lt;/div&gt;
</code></pre>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1770357897235/488b63a8-b520-4b3e-b83b-1b18a316f23d.png" alt="gap y 5" style="display: block;" width="120" height="305" loading="lazy">

<p><strong>Utility classes</strong>:</p>
<ul>
<li><p><code>gap-&lt;number&gt;</code>: Applies space (x-axis by default) between items according to the number, as shown in the example.</p>
</li>
<li><p><code>gap-[&lt;custom-property&gt;]</code>: You can apply a custom gap inside square brackets, such as <code>gap-[10px]</code>.</p>
</li>
<li><p><code>gap-x-&lt;number&gt;</code>: Provides horizontal spacing only.</p>
</li>
<li><p><code>gap-y-&lt;number&gt;</code>: Provides vertical spacing only.</p>
</li>
</ul>
<h3 id="heading-responsive-design">Responsive Design</h3>
<p>You can prefix&nbsp;the <code>gap</code>, <code>column-gap</code>,&nbsp;and&nbsp;<code>row-gap</code>&nbsp;utilities&nbsp;with a breakpoint variant, like&nbsp;<code>lg:</code>&nbsp;to only apply the utility at&nbsp;larger&nbsp;screen sizes and above. Here's an example:</p>
<pre><code class="language-xml">&lt;div class="flex gap-4 lg:gap-8 ..."&gt;
  &lt;!-- ... --&gt;
&lt;/div&gt;
</code></pre>
<h2 id="heading-how-to-justify-and-align-flex-items-in-tailwind">How to Justify and Align Flex Items in Tailwind</h2>
<p>If you're building interactive components like dropdowns, menus, or toolbars using Flexbox, alignment becomes even more important when handling keyboard navigation.</p>
<p>For example, when using arrow keys to navigate horizontally aligned items (<code>justify-between</code>, <code>justify-center</code>, and so on), proper spacing ensures a better user experience. You can explore how <a href="https://flyonui.com/docs/content/keyboard">Tailwind CSS keyboard</a> navigation works with <a href="https://flyonui.com/docs/content/keyboard/#arrow-keys">arrow keys</a> in FlyonUI.</p>
<p>FlyonUI provides accessible <a href="https://flyonui.com/docs/component/">Tailwind components</a> that integrate smoothly with Tailwind CSS, especially helpful when building flex-based navigation layouts.</p>
<p>Tailwind CSS offers a wide range of utility classes for aligning and justifying flex items, which can sometimes be confusing to differentiate. Below is a concise overview of these classes, along with practical examples.</p>
<h3 id="heading-justify-content">justify-content</h3>
<p><a href="https://tailwindcss.com/docs/justify-content">justify-content</a> is a flexbox property that controls how flex items are aligned along the main axis of a flex container. It decides how items are spaced inside a flex container. It is applied along with class <code>flex</code>.</p>
<p>Here's an example:</p>
<pre><code class="language-xml">&lt;div class="flex justify-start gap-2"&gt;
	&lt;div&gt;01&lt;div&gt;
	&lt;div&gt;02&lt;div&gt;
	&lt;div&gt;03&lt;div&gt;
&lt;/div&gt;
</code></pre>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1770358388754/3fc9155b-067b-4ebd-9b75-037da1b34a00.png" alt="Justify Content" style="display: block;" width="957" height="546" loading="lazy">

<p><strong>Utility classes</strong>:</p>
<ul>
<li><p><code>justify-start</code>: Aligns items at the start of the container.</p>
</li>
<li><p><code>justify-center</code>: Centers items along the main axis.</p>
</li>
<li><p><code>justify-end</code>: Aligns items at the end of the container.</p>
</li>
<li><p><code>justify-between</code>: Adds space between items, pushing first and last items to the edges.</p>
</li>
<li><p><code>justify-around</code>: Adds equal space around each item.</p>
</li>
<li><p><code>justify-evenly</code>: Distributes items with equal spacing everywhere, including edges.</p>
</li>
</ul>
<h3 id="heading-align-items">Align Items</h3>
<p><a href="https://tailwindcss.com/docs/align-items">align-items</a> is a flexbox property that controls how flex items are aligned along the <strong>cross-axis</strong> of a flex container.</p>
<p>In a row-based flex container (<code>flex-row</code>, which is the default direction), the cross axis is <strong>vertical</strong>. That means <code>align-items</code> controls vertical alignment.</p>
<p>In a column-based container (<code>flex-col</code>), the cross axis becomes <strong>horizontal</strong>, so <code>align-items</code> controls horizontal alignment instead.</p>
<p>This property is applied alongside the <code>flex</code> class and is commonly used to align items consistently inside navigation bars, toolbars, cards, and forms.</p>
<pre><code class="language-xml">&lt;div class="flex items-start gap-2"&gt;
	&lt;div&gt;01&lt;/div&gt;
	&lt;div&gt;02&lt;/div&gt;
	&lt;div&gt;03&lt;/div&gt;
&lt;/div&gt;
</code></pre>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1770358590807/6440854e-822a-449d-ab22-fc417916bc45.png" alt="align text flexbox" style="display: block;" width="917" height="618" loading="lazy">

<p><strong>Utility classes</strong>:</p>
<ul>
<li><p><code>items-start</code>: Aligns items to the start of the cross-axis (top in a row).</p>
</li>
<li><p><code>items-center</code>: Centers items vertically along the cross-axis.</p>
</li>
<li><p><code>items-end</code>: Aligns items to the end of the cross axis (bottom in a row).</p>
</li>
<li><p><code>items-baseline</code>: Aligns items based on their text baseline.</p>
</li>
<li><p><code>items-stretch</code>: Stretches items to fill the container (default behavior).</p>
</li>
</ul>
<h2 id="heading-practice-flexbox-with-interactive-games">Practice Flexbox with Interactive Games</h2>
<p>Reading documentation is important, but Flexbox really <em>clicks</em> when you practice it visually. One of the best ways to build strong Flexbox intuition is through interactive games that let you experiment with alignment, spacing, and direction in real time.</p>
<p>Here are two excellent games that will strengthen your Flexbox fundamentals and make Tailwind’s flex utilities feel second nature:</p>
<h3 id="heading-flexbox-froggy">Flexbox Froggy</h3>
<p>🔗 <a href="https://flexboxfroggy.com/">https://flexboxfroggy.com/</a></p>
<p>Flexbox Froggy is a fun and beginner-friendly game where you help frogs reach their lily pads using Flexbox properties. Each level introduces a new concept, like <code>justify-content</code>, <code>align-items</code>, <code>flex-direction</code>, and <code>flex-wrap</code>.</p>
<p><strong>Why it’s great:</strong></p>
<ul>
<li><p>Perfect for beginners</p>
</li>
<li><p>Visual feedback makes concepts easy to grasp</p>
</li>
<li><p>Covers core Flexbox properties step by step</p>
</li>
</ul>
<p>If you’re new to Flexbox, this is one of the best places to start.</p>
<h3 id="heading-flexbox-adventure-coding-fantasy">Flexbox Adventure (Coding Fantasy)</h3>
<p>🔗 <a href="https://codingfantasy.com/games/flexboxadventure">https://codingfantasy.com/games/flexboxadventure</a></p>
<p>Flexbox Adventure turns Flexbox learning into a role-playing game where you move your character by writing Flexbox rules. It focuses more on real-world layout thinking and helps reinforce how different properties work together.</p>
<p><strong>Why it’s great:</strong></p>
<ul>
<li><p>More challenging than Flexbox Froggy</p>
</li>
<li><p>Helps solidify intermediate concepts</p>
</li>
<li><p>Encourages problem-solving with Flexbox logic</p>
</li>
</ul>
<p>This is a great follow-up once you’re comfortable with the basics.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Flexbox is a core part of modern CSS layouts, and Tailwind CSS makes it even more powerful by turning Flexbox properties into simple, readable utility classes. By understanding utilities for direction, sizing, wrapping, spacing, ordering, and alignment, you can build responsive and flexible layouts without writing custom CSS.</p>
<p>And by understanding how properties like <code>flex</code>, <code>grow</code>, <code>shrink</code>, <code>basis</code>, <code>justify-*</code>, <code>items-*</code>, <code>gap</code>, when responsive variants work together, you can build layouts that are not only flexible and responsive but also maintainable and scalable.</p>
<p>Instead of wrestling with custom CSS, Tailwind allows you to express layout intent directly in your markup, keeping your workflow fast and predictable.</p>
<p>With these Flexbox fundamentals in your toolkit, you’re well-equipped to design clean, responsive interfaces using Tailwind CSS with confidence. 🚀</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How Does an MCP Work Under the Hood? MCP Workflow Explained ]]>
                </title>
                <description>
                    <![CDATA[ We’ve all faced that awkward limitation with AI: it can write code or explain complex topics in seconds, but the moment you ask it to check a local file or run a quick database query, it hits a wall. It’s like having a genius assistant who is locked ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-does-an-mcp-work-under-the-hood/</link>
                <guid isPermaLink="false">6941a65f3076ac3edd6fdaf0</guid>
                
                    <category>
                        <![CDATA[ mcp ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Model Context Protocol ]]>
                    </category>
                
                    <category>
                        <![CDATA[ AI ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Ajay Patel ]]>
                </dc:creator>
                <pubDate>Tue, 16 Dec 2025 18:35:11 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/upload/v1765909617721/fa533504-3dab-48c3-9b92-0b89a81af025.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>We’ve all faced that awkward limitation with AI: it can write code or explain complex topics in seconds, but the moment you ask it to check a local file or run a quick database query, it hits a wall. It’s like having a genius assistant who is locked in an empty room—smart, but completely cut off from your actual work. This is where the Model Context Protocol (MCP) changes the game. In this article, we’ll explore MCP in depth.</p>
<h2 id="heading-table-of-contents">Table of Contents</h2>
<ul>
<li><p><a class="post-section-overview" href="#heading-mcp-server-a-z-of-model-context-protocol">MCP Server: A-Z of Model Context Protocol</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-is-mcp-model-context-protocol">What is MCP (Model Context Protocol)?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-architecture-of-mcp">Architecture of MCP</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-does-mcp-work">How Does MCP Work?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-mcp-vs-rag">MCP vs RAG</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-mcp-vs-a2a">MCP vs A2A</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-resources">Resources</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-conclusion">Conclusion</a></p>
</li>
</ul>
<h2 id="heading-mcp-server-a-z-of-model-context-protocol">MCP Server: A-Z of Model Context Protocol</h2>
<p>LLMs possess impressive knowledge and reasoning skills, which allow them to perform many complex tasks. But the problem is that their knowledge is limited to their initial training data. It means they can’t access your calendar, run SQL queries, or send an email.</p>
<p>It was clear that, to give the LLMs real-world knowledge, we have to provide some integrations that enable them to access real-time knowledge or perform some actions in the real world. This leads to the classic MxN problems, where developers have to build and maintain custom integrations for every combination of M models and N tools.</p>
<p>The image below properly demonstrates the MxN Problem:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1764841852514/f4279e47-416d-4559-8908-16199eab3820.jpeg" alt="mxn problem - connecting every model to every tool individually" class="image--center mx-auto" width="2816" height="1536" loading="lazy"></p>
<p>Function calling (also known as tool calling) provides a powerful and flexible way for OpenAI models to interface with external systems and access data outside their training data. However, this feature is currently exclusive to OpenAI models, creating vendor lock-in.</p>
<p>That’s where MCP steps in. MCP is a write once, use anywhere approach to the problem. An app developer can write a single MCP server for any AI system to use and expose a set of tools and data. Similarly, an AI system can implement the protocol and connect to any MCP server that exists today or in the future.</p>
<h2 id="heading-what-is-mcp-model-context-protocol">What is MCP (Model Context Protocol)?</h2>
<p>MCP is an open-source standard, developed by Anthropic, for connecting AI applications to external systems.</p>
<p>By using an MCP, AI applications like Claude or ChatGPT can connect to data sources like local files and databases, tools like search engines and calculators, and workflows like specialized prompts—enabling them to access key information and perform tasks.</p>
<p>Think of an MCP like a USB-C port for AI applications. Just as USB-C provides a standardized way to connect electronic devices, an MCP provides a standardized way to connect AI applications to external systems.</p>
<p>The image below will help you to better understand the MCP Server:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1764763126029/45a8d0a7-a4f4-47e4-afb9-268930bd1c47.png" alt="structure of model context protocol" class="image--center mx-auto" width="1024" height="559" loading="lazy"></p>
<h2 id="heading-architecture-of-mcp">Architecture of MCP</h2>
<p>The Model Context Protocol has a clear structure with components that work together to help LLMs and outside systems interact easily. An MCP follows a simple client-server architecture, which can be broken down into three simple key components:</p>
<h3 id="heading-mcp-host"><strong>MCP Host</strong></h3>
<p>The host is the user-facing AI application, the environment where the AI model lives and interacts with the user. Hosts manage the discovery, permissions, and communication between clients and servers. This ca be a chat application like OpenAI’s ChatGPT interface or Anthropic’s Claude desktop app, or an AI-enhanced IDE like Cursor &amp; Windsurf.</p>
<h3 id="heading-mcp-client"><strong>MCP Client</strong></h3>
<p>The MCP client is a component within the host that handles the low-level communication with the MCP server. MCP clients are instantiated by host applications to communicate with particular MCP servers. Each client handles one direct communication with one server.</p>
<p>Here, the difference is important: the host is the application users interact with, while clients are the components that enable server connections.</p>
<h3 id="heading-mcp-server"><strong>MCP Server</strong></h3>
<p>The MCP server is the external program or service that exposes the capabilities (tools, data, and so on) to the application. An MCP server can be seen as a wrapper around some functionality, which exposes a set of tools or resources in a standardized way so that any MCP client can invoke them.</p>
<p>Servers can run locally on the same machine as the host, or remotely on some cloud service, since an MCP is designed to support both scenarios seamlessly</p>
<p>The image below will help you to better understand the concept:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1764841995822/fdec43d4-705e-4385-8eac-b436ec22c386.jpeg" alt="how does mcp work" class="image--center mx-auto" width="2976" height="1440" loading="lazy"></p>
<p>An MCP server can expose one or more capabilities to the client. Capabilities are essentially the features or functions that the server makes available.</p>
<p>The MCP server provides the following capabilities:</p>
<ul>
<li><p><strong>Tools:</strong> Tools are the functions that do something on behalf of the AI model. An AI can use this tool whenever required. Tools are triggered by the AI model’s choice, which means the LLM (via the host) decides to call a tool when it determines it needs to perform a specific task. For example: send_email -&gt; send the email to the user</p>
</li>
<li><p><strong>Resources:</strong> Resources provide read-only data to the AI model. A resource can be a database record or a knowledge base that the AI can query to get information, but can’t modify.</p>
</li>
<li><p><strong>Prompts:</strong> Prompts are the predefined templates or workflows that the server can provide.</p>
</li>
</ul>
<h3 id="heading-transport-layer"><strong>Transport Layer</strong></h3>
<p>The transport layer uses JSON-RPC 2.0 messages to communicate between the client and server. For this, we have mainly two transport methods:</p>
<ul>
<li><p><strong>Standard Input/Output (stdio):</strong> Ideal for local environments, providing fast and synchronous message transmission.</p>
</li>
<li><p><strong>Server-Sent Events (SSE):</strong> Best suited for remote resources, enabling efficient, real-time, one-way data streaming from the server to the client.</p>
</li>
</ul>
<h2 id="heading-how-does-mcp-work">How Does MCP Work?</h2>
<p>An MCP gives an AI assistant the ability to securely use external tools, databases, and services. Imagine you ask Claude:</p>
<blockquote>
<p>“Find the latest sales report in our database and email it to my manager.”</p>
</blockquote>
<h3 id="heading-step-1-tool-discovery"><strong>Step #1 - Tool Discovery</strong></h3>
<p>When we launch any MCP client (Claude Desktop), it connects to your configured MCP servers and asks: “What can I do with available tools?”</p>
<p>Each server responds with its available tools:</p>
<p><code>database_query</code> ,<code>email_sender</code> ,<code>file_browser</code></p>
<p>Now, Claude knows about the tools it has.</p>
<h3 id="heading-step-2-understanding-your-requirement"><strong>Step #2 - Understanding Your Requirement</strong></h3>
<p>Claude reads your query and realizes:</p>
<ul>
<li><p>It needs to retrieve information it doesn’t have (in this case, it has to find the sales data <code>database_query</code>)</p>
</li>
<li><p>It needs to take an external action (send email <code>email_sender</code> )</p>
</li>
</ul>
<p>So Claude plans a 2-step tool sequence.</p>
<h3 id="heading-step-3-ask-for-permission"><strong>Step #3 - Ask for Permission</strong></h3>
<p>Before any external action happens, Claude Desktop prompts you: “Claude wants to query your sales database. Allow?”</p>
<p>Nothing proceeds without your approval. This is core to the MCP’s security model.</p>
<h3 id="heading-step-4-querying-the-database"><strong>Step #4 - Querying the Database</strong></h3>
<p>Once you grant the permission, Claude sends a structured MCP tool call to the <code>database_query</code> server.</p>
<p>Next, the server will run a secure database lookup and return the latest sales report data. This doesn’t give Claude direct access to the database.</p>
<h3 id="heading-step-5-sending-the-email"><strong>Step #5 - Sending the Email</strong></h3>
<p>Once Claude has the data, Claude triggers a second permission prompt: “Claude wants to send an email on your behalf. Approve?”</p>
<p>Once approved, MCP sends the information to the <code>email_sender</code> server, and Claude will format the email &amp; deliver it to your manager</p>
<h3 id="heading-step-6-natural-answer"><strong>Step #6 - Natural Answer</strong></h3>
<p>Claude wraps everything up nicely and sends a response to you, “Done! I found the latest sales report and emailed it to your manager.”</p>
<p>The entire process typically happens in seconds. From your perspective, Claude simply "knows" how to access your database and send emails, but in reality, the MCP has orchestrated a secure, standardized exchange between multiple systems.</p>
<p>The beauty of MCP is that it transforms AI assistants from isolated conversational tools into genuine productivity partners that can interact with your entire digital ecosystem, safely and with your explicit permission every step of the way.</p>
<h2 id="heading-mcp-vs-rag">MCP vs RAG</h2>
<p>Fundamentally, MCP and RAG are built for serving different purposes.</p>
<p>RAG is a technique that is used to supply the relevant knowledge that we have stored in a vector database. In RAG, the user’s query is converted to a vector embedding, which searches through embeddings in the vector database and finds the relevant context based on similarity. This relevant context is then provided to the LLM. It is great for answering questions from large documents like company wikis, knowledge bases, or research papers.</p>
<p>An MCP enables AI models to perform real-world actions with the help of tools. It lets the AI connect to tools and services like databases, APIs, Gmail, calendar, and so on.</p>
<h2 id="heading-mcp-vs-a2a">MCP vs A2A</h2>
<p>The Model Context Protocol (MCP) and the Agent-to-Agent (A2A) protocol are complementary open standards in AI architecture that serve different purposes in how AI agents connect with external systems.</p>
<ul>
<li><p>MCP standardizes how a single AI agent connects to tools, data, and external systems (agent-to-tool communication).</p>
</li>
<li><p>A2A standardizes how multiple, independent AI agents communicate and collaborate with each other (agent-to-agent communication).</p>
</li>
</ul>
<h2 id="heading-resources">Resources</h2>
<p>For more information on the MCP, you can refer to the official website: <a target="_blank" href="http://modelcontextprotocol.io">modelcontextprotocol.io</a>.</p>
<p><strong>Some of the awesome MCP Servers which you can check:</strong></p>
<ul>
<li><p><a target="_blank" href="https://github.com/brave/brave-search-mcp-server">Brave Search MCP Server</a></p>
<ul>
<li>An MCP server implementation that integrates the Brave Search API, providing both web and local search capabilities.</li>
</ul>
</li>
<li><p><a target="_blank" href="https://github.com/getsentry/sentry-mcp">Sentry MCP server</a></p>
<ul>
<li>This server provides tools to inspect error reports, stacktraces, and other debugging information from your Sentry account.</li>
</ul>
</li>
<li><p><a target="_blank" href="https://developers.google.com/maps/ai/mcp">Google Maps MCP Server</a></p>
<ul>
<li>MCP Server for the Google Maps API.</li>
</ul>
</li>
<li><p><a target="_blank" href="https://flyonui.com/mcp">Tailwind MCP Server</a> by FlyonUI</p>
<ul>
<li>MCP Server for FlyoUI - Generate Amazing UIs/Themes/Sections with just a single prompt.</li>
</ul>
</li>
<li><p><a target="_blank" href="https://github.com/idosal/git-mcp">git MCP server</a></p>
<ul>
<li>A Model Context Protocol server for Git repository interaction and automation. This server provides tools to read, search, and manipulate Git repositories via Large Language Models.</li>
</ul>
</li>
<li><p><a target="_blank" href="https://github.com/github/github-mcp-server">GitHub MCP Server</a></p>
<ul>
<li>MCP Server for the GitHub API, enabling file operations, repository management, search functionality, and more.</li>
</ul>
</li>
<li><p><a target="_blank" href="https://shadcnstudio.com/mcp">Shadcn MCP Server</a></p>
<ul>
<li>MCP Server for shadcn/studio - Generate Amazing UIs/Themes/Sections with just a single prompt.</li>
</ul>
</li>
</ul>
<p>You can explore a list of available MCP servers here: <a target="_blank" href="https://github.com/punkpeye/awesome-mcp-servers">https://github.com/punkpeye/awesome-mcp-servers</a></p>
<p>If you're interested in learning how to build your own MCP server, check out this detailed course on Hugging Face: <a target="_blank" href="https://huggingface.co/mcp-course**">https://huggingface.co/mcp-course</a>.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>MCP (Model Context Protocol) is an open-source standard for connecting AI applications to external systems. With MCP, AI models are not just chatbots, they are fully capable agents that can work with your local files, query your database, send emails with your permission and control.</p>
<p>It has also solved the classic MxN problem—developers only need to build the MCP server once, then all other AI systems can integrate the MCP server in their application.</p>
<p>MCP is the revolution in how AI systems can interact with the real world. As the ecosystem of the MCP continues to grow, it will enable AI agents to become more powerful assistants that can operate across diverse environments with reliability and security.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Build an Admin Dashboard with shadcn/ui and TanStack Start ]]>
                </title>
                <description>
                    <![CDATA[ In this guide, we’ll build a feature-rich admin dashboard using shadcn/ui for beautiful, reusable components and TanStack Start for a powerful, type-safe full-stack framework. By the end, you’ll have: A fully functional /dashboard layout A statisti... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/build-an-admin-dashboard-with-shadcnui-and-tanstack-start/</link>
                <guid isPermaLink="false">6931bd617fcd342128f08ed6</guid>
                
                    <category>
                        <![CDATA[ shadcn ]]>
                    </category>
                
                    <category>
                        <![CDATA[ shadcnui ]]>
                    </category>
                
                    <category>
                        <![CDATA[ shadcn ui ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tanstack-start ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tanstack ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Ajay Patel ]]>
                </dc:creator>
                <pubDate>Thu, 04 Dec 2025 16:57:05 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/upload/v1764780775287/b8cb826d-ac42-497c-8bb9-b9ffe797df83.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>In this guide, we’ll build a feature-rich admin dashboard using shadcn/ui for beautiful, reusable components and TanStack Start for a powerful, type-safe full-stack framework.</p>
<p>By the end, you’ll have:</p>
<ul>
<li><p>A fully functional <code>/dashboard</code> layout</p>
</li>
<li><p>A statistics-rich dashboard home page with charts and tables</p>
</li>
<li><p>A Products page using TanStack Query and TanStack Table</p>
</li>
<li><p>A Settings page with profile and notification controls</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1764155564957/eda17d57-3f13-4526-be89-be55ec27453c.png" alt="TanStack Start dashboard" class="image--center mx-auto" width="1905" height="1050" loading="lazy"></p>
<h2 id="heading-table-of-contents">Table of Contents</h2>
<ol>
<li><p><a class="post-section-overview" href="#heading-why-tanstack-start">Why TanStack Start?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-why-shadcnui">Why shadcn/ui?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-build-the-admin-dashboard-using-shadcnui-and-tanstack-start">How to Build the Admin Dashboard Using shadcn/ui and TanStack Start</a></p>
<ul>
<li><p><a class="post-section-overview" href="#heading-1-create-a-new-tanstack-app">1. Create a new TanStack app</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-2-initial-cleanup">2. Initial Cleanup</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-3-setting-up-shadcnstudio-blocks">3. Setting Up shadcn/studio Blocks</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-4-routing-structure-for-the-dashboard">4. Routing Structure for the Dashboard</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-5-creating-the-dashboard-layout">5. Creating the /dashboard Layout</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-6-building-the-dashboard-home-page">6. Building the Dashboard Home Page</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-7-set-up-the-products-page">7. Set up the Products Page.</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-8-settings-page">8. Settings Page</a></p>
</li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-live-demo-amp-source-code">Live Demo &amp; Source Code</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-summary">Summary</a></p>
<ul>
<li><p><a class="post-section-overview" href="#heading-whats-next">What’s Next?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-resources">Resources:</a></p>
</li>
</ul>
</li>
</ol>
<h3 id="heading-prerequisites">Prerequisites</h3>
<p>Before we start the guide, let’s understand the basic requirements of the project:</p>
<ul>
<li><p>Node.js 18+ installed</p>
</li>
<li><p>Basic knowledge of React and TypeScript</p>
</li>
<li><p>Familiarity with TailwindCSS</p>
</li>
</ul>
<h3 id="heading-what-we-will-build">What we will build</h3>
<p>In this article, we’ll build a fully functional admin dashboard with three main sections:</p>
<ol>
<li><p><strong>Dashboard overview</strong>: A home page that displays various charts showing sales metrics, product insights widgets, and a transaction history table.</p>
</li>
<li><p><strong>Products:</strong> A product page that demonstrates data fetching, server-side pagination, and advanced table features like column searching, sorting, and column filtering.</p>
</li>
<li><p><strong>Settings:</strong> A user-friendly settings page with profile management and notification preferences.</p>
</li>
</ol>
<p>The dashboard will include a responsive sidebar navigation, breadcrumb trails, a user profile dropdown, and a language selector.</p>
<h2 id="heading-why-tanstack-start">Why TanStack Start?</h2>
<p><a target="_blank" href="https://tanstack.com/start/latest">TanStack Start</a> is a modern full-stack React framework built on top of TanStack Router. It aims to be a flexible, type-safe alternative to traditional meta-frameworks like Next.js.</p>
<p>Some key benefits of TanStack Start include:</p>
<ul>
<li><p>Type-safe routing and data loading</p>
</li>
<li><p>Server-side rendering (SSR) out of the box</p>
</li>
<li><p>Built on TanStack Router, with file-based routing</p>
</li>
<li><p>Great DX with TypeScript and TanStack Query integration</p>
</li>
</ul>
<p>We’ll pair it with shadcn/ui to quickly build a polished admin dashboard.</p>
<h2 id="heading-why-shadcnui">Why shadcn/ui?</h2>
<p><a target="_blank" href="https://ui.shadcn.com/">shadcn/ui</a> is a collection of beautifully designed, accessible React components built on top of Radix UI and styled with Tailwind CSS.</p>
<p>Instead of installing a package, you can copy and paste the component's code directly into your project or use a CLI to generate it. This gives you full control over the code structure &amp; styling. This approach makes Shadcn highly customizable for frameworks like TanStack Start, Next.js, Astro, and so on.</p>
<h2 id="heading-how-to-build-the-admin-dashboard-using-shadcnui-and-tanstack-start">How to Build the Admin Dashboard Using shadcn/ui and TanStack Start</h2>
<h3 id="heading-1-create-a-new-tanstack-app">1. Create a new TanStack app</h3>
<p>To get started, you’ll need to create a new TanStack Start app. You can do that with the following command:</p>
<pre><code class="lang-typescript">pnpm create <span class="hljs-meta">@tanstack</span>/start<span class="hljs-meta">@latest</span>
</code></pre>
<p>During the CLI setup, when it asks about add-ons, make sure to select:</p>
<ul>
<li><p>Shadcn</p>
</li>
<li><p>Table</p>
</li>
<li><p>Query</p>
</li>
</ul>
<p>These will give you the shadcn/ui setup and the TanStack Query + Table integrations we’ll use later.</p>
<h3 id="heading-2-initial-cleanup">2. Initial Cleanup</h3>
<p>TanStack Start’s starter template comes with some demo routes and a header we don’t need.</p>
<p>Clean up the project as follows:</p>
<ol>
<li><p>Remove the demo folder inside the <code>src/routes</code> directory (or wherever your router directory lives).</p>
</li>
<li><p>Delete <code>Header.tsx</code> from <code>src/components</code>.</p>
</li>
<li><p>Remove the <code>Header</code> import and usage from <code>src/routes/__root.tsx</code>.</p>
</li>
<li><p>Clean up the <code>src/routes/index.tsx</code> file to something minimal (or leave a simple landing page).</p>
</li>
</ol>
<p>At this point, you can make the initial commit to your repo.</p>
<h3 id="heading-3-setting-up-shadcnstudio-blocks">3. Setting Up shadcn/studio Blocks</h3>
<p>Before we set up, let’s make sure you’re clear on what the shadcn/studio and Shadcn registries are.</p>
<h4 id="heading-what-is-shadcnstudio">What is shadcn/studio?</h4>
<p><a target="_blank" href="https://shadcnstudio.com">shadcn/studio</a> is an open-source collection of copy-and-paste shadcn/ui components, blocks, and templates. It’s paired with a powerful shadcn theme generator to help you craft, customize, and ship faster.</p>
<h4 id="heading-what-is-shadcn-registry">What is Shadcn Registry?</h4>
<p>A shadcn registry is a system for sharing and distributing reusable code assets such as UI components, hooks, and theme configurations across different projects. Running your own registry allows you to publish your custom components that others can then use. The registry uses a <code>registry.json</code> file to define and organize the components and their associated files. </p>
<p>If you want to know more about registries, you can refer to the <a target="_blank" href="https://ui.shadcn.com/docs/registry">official documentation here</a>.</p>
<p>For quick building, we will use shadcn/studio’s free shadcn block – dashboard shell.</p>
<p>First, configure the registries in your <code>components.json</code>:</p>
<pre><code class="lang-typescript">{
  <span class="hljs-comment">// ...existing config</span>
  <span class="hljs-string">"registries"</span>: {
    <span class="hljs-string">"@shadcn-studio"</span>: <span class="hljs-string">"https://shadcnstudio.com/r/{name}.json"</span>,
    <span class="hljs-string">"@ss-components"</span>: <span class="hljs-string">"https://shadcnstudio.com/r/components/{name}.json"</span>,
    <span class="hljs-string">"@ss-blocks"</span>: <span class="hljs-string">"https://shadcnstudio.com/r/blocks/{name}.json"</span>,
    <span class="hljs-string">"@ss-themes"</span>: <span class="hljs-string">"https://shadcnstudio.com/r/themes/{name}.json"</span>
  }
}
</code></pre>
<p>If you face any issues while setting up, you can refer to the <a target="_blank" href="https://shadcnstudio.com/docs/getting-started/how-to-use-shadcn-cli">docs</a>.</p>
<h4 id="heading-install-the-dashboard-shell-block">Install the Dashboard Shell Block</h4>
<p>To get started, visit <a target="_blank" href="https://shadcnstudio.com/blocks">Shadcn blocks</a> and navigate to the Dashboard and App section. Then select the <a target="_blank" href="https://shadcnstudio.com/blocks/dashboard-and-application/dashboard-shell#dashboard-shell-1">Dashboard Shell 1</a> block (it’s free to use).</p>
<p>On the top-right, you’ll see a command to install the block into your project:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1764155098742/23d1bee2-e082-4b19-860a-8112fe6bf41c.png" alt="shadcn/stuidio dashboard shell " class="image--center mx-auto" width="1232" height="725" loading="lazy"></p>
<p>Copy that command, paste it into your terminal, and run it. This will install all the components needed for the dashboard layout (sidebar, header, dropdowns, and so on).</p>
<h3 id="heading-4-routing-structure-for-the-dashboard">4. Routing Structure for the Dashboard</h3>
<p>Next, we’ll set up the dashboard routes.</p>
<p>First, create a new layout route for <code>/dashboard</code> by adding a file at:</p>
<p><code>src/routes/dashboard.tsx</code></p>
<p>Then, inside a <code>dashboard</code> directory, create the three pages that will live under this layout:</p>
<ul>
<li><p><code>src/routes/dashboard/index.tsx</code> – main dashboard overview</p>
</li>
<li><p><code>src/routes/dashboard/products.tsx</code> – products table page</p>
</li>
<li><p><code>src/routes/dashboard/settings.tsx</code> – settings page</p>
</li>
</ul>
<p>Your <code>routes</code> folder should look like this:</p>
<pre><code class="lang-typescript">src/routes/
├── __root.tsx
├── index.tsx
├── dashboard.tsx          <span class="hljs-comment">// Layout for all /dashboard/* pages</span>
└── dashboard/
    ├── index.tsx          <span class="hljs-comment">// /dashboard</span>
    ├── products.tsx       <span class="hljs-comment">// /dashboard/products</span>
    └── settings.tsx       <span class="hljs-comment">// /dashboard/settings</span>
</code></pre>
<h3 id="heading-5-creating-the-dashboard-layout">5. Creating the <code>/dashboard</code> Layout</h3>
<p>This will set up the layout for the dashboard. Create <code>src/routes/dashboard.tsx</code> and paste:</p>
<p>file: <code>src/routes/dashboard.tsx</code></p>
<pre><code class="lang-typescript"><span class="hljs-keyword">import</span> LanguageDropdown <span class="hljs-keyword">from</span> <span class="hljs-string">'@/components/shadcn-studio/blocks/dropdown-language'</span>
<span class="hljs-keyword">import</span> ProfileDropdown <span class="hljs-keyword">from</span> <span class="hljs-string">'@/components/shadcn-studio/blocks/dropdown-profile'</span>
<span class="hljs-keyword">import</span> { Avatar, AvatarImage } <span class="hljs-keyword">from</span> <span class="hljs-string">'@/components/ui/avatar'</span>
<span class="hljs-keyword">import</span> {
    Breadcrumb,
    BreadcrumbItem,
    BreadcrumbLink,
    BreadcrumbList,
    BreadcrumbPage,
    BreadcrumbSeparator
} <span class="hljs-keyword">from</span> <span class="hljs-string">'@/components/ui/breadcrumb'</span>
<span class="hljs-keyword">import</span> { Button } <span class="hljs-keyword">from</span> <span class="hljs-string">'@/components/ui/button'</span>
<span class="hljs-keyword">import</span> { Separator } <span class="hljs-keyword">from</span> <span class="hljs-string">'@/components/ui/separator'</span>
<span class="hljs-keyword">import</span> {
    Sidebar,
    SidebarContent,
    SidebarGroup,
    SidebarGroupContent,
    SidebarGroupLabel,
    SidebarHeader,
    SidebarMenu,
    SidebarMenuButton,
    SidebarMenuItem,
    SidebarProvider,
    SidebarTrigger
} <span class="hljs-keyword">from</span> <span class="hljs-string">'@/components/ui/sidebar'</span>
<span class="hljs-keyword">import</span> { createFileRoute, Link, Outlet, useLocation } <span class="hljs-keyword">from</span> <span class="hljs-string">'@tanstack/react-router'</span>
<span class="hljs-keyword">import</span> {
    FacebookIcon,
    InstagramIcon,
    LanguagesIcon,
    LayoutDashboard,
    LinkedinIcon,
    LogIn,
    Package,
    Settings,
    TwitterIcon,
    User2
} <span class="hljs-keyword">from</span> <span class="hljs-string">'lucide-react'</span>
<span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>

<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> Route = createFileRoute(<span class="hljs-string">'/dashboard'</span>)({
    component: DashboardLayout
})

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">DashboardLayout</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">const</span> location = useLocation()
    <span class="hljs-keyword">const</span> pathSegments = location.pathname.split(<span class="hljs-string">'/'</span>).filter(<span class="hljs-built_in">Boolean</span>)

    <span class="hljs-keyword">return</span> (
        &lt;div className=<span class="hljs-string">'flex min-h-dvh w-full'</span>&gt;
            &lt;SidebarProvider&gt;
                &lt;Sidebar&gt;
                    &lt;SidebarContent&gt;
                        &lt;SidebarHeader&gt;
                            &lt;SidebarMenu&gt;
                                &lt;SidebarMenuItem&gt;
                                    &lt;SidebarMenuButton size=<span class="hljs-string">"lg"</span> asChild&gt;
                                        &lt;Link to=<span class="hljs-string">"/"</span>&gt;
                                            &lt;div className=<span class="hljs-string">"flex aspect-square size-8 items-center justify-center rounded-lg bg-primary text-primary-foreground"</span>&gt;
                                                &lt;User2 className=<span class="hljs-string">"size-4"</span> /&gt;
                                            &lt;/div&gt;
                                            &lt;div className=<span class="hljs-string">"grid flex-1 text-left text-sm leading-tight"</span>&gt;
                                                &lt;span className=<span class="hljs-string">"truncate font-semibold"</span>&gt;Your App&lt;/span&gt;
                                                &lt;span className=<span class="hljs-string">"truncate text-xs"</span>&gt;Dashboard&lt;/span&gt;
                                            &lt;/div&gt;
                                        &lt;/Link&gt;
                                    &lt;/SidebarMenuButton&gt;
                                &lt;/SidebarMenuItem&gt;
                            &lt;/SidebarMenu&gt;
                        &lt;/SidebarHeader&gt;

                        &lt;SidebarGroup&gt;
                            &lt;SidebarGroupLabel&gt;General&lt;/SidebarGroupLabel&gt;
                            &lt;SidebarGroupContent&gt;
                                &lt;SidebarMenu&gt;
                                    &lt;SidebarMenuItem&gt;
                                        &lt;SidebarMenuButton asChild&gt;
                                            &lt;Link to=<span class="hljs-string">'/dashboard'</span>&gt;
                                                &lt;LayoutDashboard /&gt;
                                                &lt;span&gt;Dashboard&lt;/span&gt;
                                            &lt;/Link&gt;
                                        &lt;/SidebarMenuButton&gt;
                                    &lt;/SidebarMenuItem&gt;
                                    &lt;SidebarMenuItem&gt;
                                        &lt;SidebarMenuButton asChild&gt;
                                            &lt;Link to=<span class="hljs-string">'/dashboard/products'</span>&gt;
                                                &lt;Package /&gt;
                                                &lt;span&gt;Products&lt;/span&gt;
                                            &lt;/Link&gt;
                                        &lt;/SidebarMenuButton&gt;
                                    &lt;/SidebarMenuItem&gt;
                                    &lt;SidebarMenuItem&gt;
                                        &lt;SidebarMenuButton asChild&gt;
                                            &lt;Link to=<span class="hljs-string">'/dashboard/settings'</span>&gt;
                                                &lt;Settings /&gt;
                                                &lt;span&gt;Settings&lt;/span&gt;
                                            &lt;/Link&gt;
                                        &lt;/SidebarMenuButton&gt;
                                    &lt;/SidebarMenuItem&gt;
                                &lt;/SidebarMenu&gt;
                            &lt;/SidebarGroupContent&gt;
                        &lt;/SidebarGroup&gt;
                    &lt;/SidebarContent&gt;
                &lt;/Sidebar&gt;
                &lt;div className=<span class="hljs-string">'flex flex-1 flex-col'</span>&gt;
                    &lt;header className=<span class="hljs-string">'bg-card sticky top-0 z-50 border-b'</span>&gt;
                        &lt;div className=<span class="hljs-string">'mx-auto flex max-w-7xl items-center justify-between gap-6 px-4 py-2 sm:px-6'</span>&gt;
                            &lt;div className=<span class="hljs-string">'flex items-center gap-4'</span>&gt;
                                &lt;SidebarTrigger className=<span class="hljs-string">'[&amp;_svg]:h-5 [&amp;_svg]:w-5'</span> /&gt;
                                &lt;Separator orientation=<span class="hljs-string">'vertical'</span> className=<span class="hljs-string">'hidden h-4 sm:block'</span> /&gt;
                                &lt;Breadcrumb className=<span class="hljs-string">'hidden sm:block'</span>&gt;
                                    &lt;BreadcrumbList&gt;
                                        &lt;BreadcrumbItem&gt;
                                            &lt;BreadcrumbLink asChild&gt;
                                                &lt;Link to=<span class="hljs-string">'/'</span>&gt;Home&lt;/Link&gt;
                                            &lt;/BreadcrumbLink&gt;
                                        &lt;/BreadcrumbItem&gt;
                                        &lt;BreadcrumbSeparator /&gt;
                                        {pathSegments.map(<span class="hljs-function">(<span class="hljs-params">segment, index</span>) =&gt;</span> {
                                            <span class="hljs-keyword">const</span> path = <span class="hljs-string">`/<span class="hljs-subst">${pathSegments.slice(<span class="hljs-number">0</span>, index + <span class="hljs-number">1</span>).join(<span class="hljs-string">'/'</span>)}</span>`</span>
                                            <span class="hljs-keyword">const</span> isLast = index === pathSegments.length - <span class="hljs-number">1</span>
                                            <span class="hljs-keyword">const</span> title = segment.charAt(<span class="hljs-number">0</span>).toUpperCase() + segment.slice(<span class="hljs-number">1</span>)

                                            <span class="hljs-keyword">return</span> (
                                                &lt;React.Fragment key={path}&gt;
                                                    &lt;BreadcrumbItem&gt;
                                                        {isLast ? (
                                                            &lt;BreadcrumbPage&gt;{title}&lt;/BreadcrumbPage&gt;
                                                        ) : (
                                                            &lt;BreadcrumbLink asChild&gt;
                                                                &lt;Link to={path <span class="hljs-keyword">as</span> <span class="hljs-built_in">any</span>}&gt;{title}&lt;/Link&gt;
                                                            &lt;/BreadcrumbLink&gt;
                                                        )}
                                                    &lt;/BreadcrumbItem&gt;
                                                    {!isLast &amp;&amp; &lt;BreadcrumbSeparator /&gt;}
                                                &lt;/React.Fragment&gt;
                                            )
                                        })}
                                    &lt;/BreadcrumbList&gt;
                                &lt;/Breadcrumb&gt;
                            &lt;/div&gt;
                            &lt;div className=<span class="hljs-string">'flex items-center gap-1.5'</span>&gt;
                                &lt;LanguageDropdown
                                    trigger={
                                        &lt;Button variant=<span class="hljs-string">'ghost'</span> size=<span class="hljs-string">'icon'</span>&gt;
                                            &lt;LanguagesIcon /&gt;
                                        &lt;/Button&gt;
                                    }
                                /&gt;
                                &lt;ProfileDropdown
                                    trigger={
                                        &lt;Button variant=<span class="hljs-string">'ghost'</span> size=<span class="hljs-string">'icon'</span> className=<span class="hljs-string">'h-10 w-10'</span>&gt;
                                            &lt;Avatar className=<span class="hljs-string">'h-10 w-10 rounded-md'</span>&gt;
                                                &lt;AvatarImage src=<span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-1.png'</span> /&gt;
                                            &lt;/Avatar&gt;
                                        &lt;/Button&gt;
                                    }
                                /&gt;
                            &lt;/div&gt;
                        &lt;/div&gt;
                    &lt;/header&gt;
                    &lt;main className=<span class="hljs-string">'mx-auto w-full max-w-7xl flex-1 px-4 py-6 sm:px-6'</span>&gt;
                        &lt;Outlet /&gt;
                    &lt;/main&gt;
                    &lt;footer&gt;
                        &lt;div className=<span class="hljs-string">'text-muted-foreground mx-auto flex w-full items-center justify-between gap-3 px-4 py-3 flex-col sm:flex-row sm:gap-6 sm:px-6'</span>&gt;
                            &lt;p className=<span class="hljs-string">'text-sm text-center sm:text-left'</span>&gt;
                                {<span class="hljs-string">`©<span class="hljs-subst">${<span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>().getFullYear()}</span>`</span>}{<span class="hljs-string">' '</span>}
                                &lt;a href=<span class="hljs-string">'#'</span> className=<span class="hljs-string">'text-primary'</span>&gt;
                                    TanStack Start
                                &lt;/a&gt;
                                , Made <span class="hljs-keyword">for</span> better web design
                            &lt;/p&gt;
                            &lt;div className=<span class="hljs-string">'flex items-center gap-5'</span>&gt;
                                &lt;a href=<span class="hljs-string">'#'</span>&gt;
                                    &lt;FacebookIcon className=<span class="hljs-string">'h-4 w-4'</span> /&gt;
                                &lt;/a&gt;
                                &lt;a href=<span class="hljs-string">'#'</span>&gt;
                                    &lt;InstagramIcon className=<span class="hljs-string">'h-4 w-4'</span> /&gt;
                                &lt;/a&gt;
                                &lt;a href=<span class="hljs-string">'#'</span>&gt;
                                    &lt;LinkedinIcon className=<span class="hljs-string">'h-4 w-4'</span> /&gt;
                                &lt;/a&gt;
                                &lt;a href=<span class="hljs-string">'#'</span>&gt;
                                    &lt;TwitterIcon className=<span class="hljs-string">'h-4 w-4'</span> /&gt;
                                &lt;/a&gt;
                            &lt;/div&gt;
                        &lt;/div&gt;
                    &lt;/footer&gt;
                &lt;/div&gt;
            &lt;/SidebarProvider&gt;
        &lt;/div&gt;
    )
}
</code></pre>
<p>You now have a full layout for all <code>/dashboard/*</code> routes.</p>
<p>Let's break down the key parts of our dashboard layout:</p>
<ul>
<li><p><strong>Sidebar structure:</strong> The <code>&lt;Sidebar&gt;</code> component wraps our navigation menu. Inside, we use <code>&lt;SidebarMenu&gt;</code> and <code>&lt;SidebarMenuItem&gt;</code> to create navigation links. Each menu item uses TanStack Router's <code>&lt;Link&gt;</code> component for type-safe navigation. We also have a header set up in the <code>&lt;SidebarProvider&gt;</code></p>
</li>
<li><p><strong>Dynamic breadcrumbs:</strong> The breadcrumb section uses <code>location.pathname</code> to split the current URL into segments, then maps over them to create breadcrumb links. The <code>isLast</code> check ensures the final breadcrumb renders as plain text rather than a link.</p>
</li>
<li><p><strong>Header actions</strong>: The header includes two dropdowns: <code>&lt;LanguageDropdown&gt;</code> for internationalization and <code>&lt;ProfileDropdown&gt;</code> for user account actions. These come from the <code>shadcn/studio</code> blocks we installed.</p>
</li>
<li><p><strong>Outlet component:</strong> The <code>&lt;Outlet /&gt;</code> component is where child routes (like <code>/dashboard</code>, <code>/dashboard/products</code>) will render. This makes our layout reusable across all dashboard pages. The layout uses Tailwind's utility classes for spacing, colors, and responsive behavior, making it easy to customize for your use case.</p>
</li>
</ul>
<p>For more details regarding the Sidebar component, you can <a target="_blank" href="https://ui.shadcn.com/docs/components/sidebar">refer to the official docs here</a>.</p>
<p>You now have a full layout for all <code>/dashboard/*</code> routes.</p>
<h3 id="heading-6-building-the-dashboard-home-page">6. Building the Dashboard Home Page</h3>
<p>Create <code>src/routes/dashboard/index.tsx</code>:</p>
<pre><code class="lang-typescript"><span class="hljs-keyword">import</span> { <span class="hljs-keyword">type</span> Item } <span class="hljs-keyword">from</span> <span class="hljs-string">'@/components/shadcn-studio/blocks/datatable-transaction'</span>
<span class="hljs-keyword">import</span> { createFileRoute } <span class="hljs-keyword">from</span> <span class="hljs-string">'@tanstack/react-router'</span>

<span class="hljs-keyword">import</span> { Card } <span class="hljs-keyword">from</span> <span class="hljs-string">'@/components/ui/card'</span>

<span class="hljs-keyword">import</span> SalesMetricsCard <span class="hljs-keyword">from</span> <span class="hljs-string">'@/components/shadcn-studio/blocks/chart-sales-metrics'</span>
<span class="hljs-keyword">import</span> TransactionDatatable <span class="hljs-keyword">from</span> <span class="hljs-string">'@/components/shadcn-studio/blocks/datatable-transaction'</span>
<span class="hljs-keyword">import</span> StatisticsCard <span class="hljs-keyword">from</span> <span class="hljs-string">'@/components/shadcn-studio/blocks/statistics-card-01'</span>
<span class="hljs-keyword">import</span> ProductInsightsCard <span class="hljs-keyword">from</span> <span class="hljs-string">'@/components/shadcn-studio/blocks/widget-product-insights'</span>
<span class="hljs-keyword">import</span> TotalEarningCard <span class="hljs-keyword">from</span> <span class="hljs-string">'@/components/shadcn-studio/blocks/widget-total-earning'</span>

<span class="hljs-keyword">import</span> {
    CalendarX2Icon,
    TriangleAlertIcon,
    TruckIcon
} <span class="hljs-keyword">from</span> <span class="hljs-string">'lucide-react'</span>

<span class="hljs-comment">// Statistics card data</span>
<span class="hljs-keyword">const</span> StatisticsCardData = [
    {
        icon: &lt;TruckIcon className=<span class="hljs-string">'h-4 w-4'</span> /&gt;,
        value: <span class="hljs-string">'42'</span>,
        title: <span class="hljs-string">'Shipped Orders'</span>,
        changePercentage: <span class="hljs-string">'+18.2%'</span>
    },
    {
        icon: &lt;TriangleAlertIcon className=<span class="hljs-string">'h-4 w-4'</span> /&gt;,
        value: <span class="hljs-string">'8'</span>,
        title: <span class="hljs-string">'Damaged Returns'</span>,
        changePercentage: <span class="hljs-string">'-8.7%'</span>
    },
    {
        icon: &lt;CalendarX2Icon className=<span class="hljs-string">'h-4 w-4'</span> /&gt;,
        value: <span class="hljs-string">'27'</span>,
        title: <span class="hljs-string">'Missed Delivery Slots'</span>,
        changePercentage: <span class="hljs-string">'+4.3%'</span>
    }
]

<span class="hljs-comment">// Earning data for Total Earning card</span>
<span class="hljs-keyword">const</span> earningData = [
    {
        img: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/blocks/dashboard-application/widgets/zipcar.png'</span>,
        platform: <span class="hljs-string">'Zipcar'</span>,
        technologies: <span class="hljs-string">'Vuejs &amp; HTML'</span>,
        earnings: <span class="hljs-string">'-$23,569.26'</span>,
        progressPercentage: <span class="hljs-number">75</span>
    },
    {
        img: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/blocks/dashboard-application/widgets/bitbank.png'</span>,
        platform: <span class="hljs-string">'Bitbank'</span>,
        technologies: <span class="hljs-string">'Figma &amp; React'</span>,
        earnings: <span class="hljs-string">'-$12,650.31'</span>,
        progressPercentage: <span class="hljs-number">25</span>
    }
]

<span class="hljs-comment">// Transaction table data</span>
<span class="hljs-keyword">const</span> transactionData: Item[] = [
    {
        id: <span class="hljs-string">'1'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-1.png'</span>,
        avatarFallback: <span class="hljs-string">'JA'</span>,
        name: <span class="hljs-string">'Jack Alfredo'</span>,
        amount: <span class="hljs-number">315.0</span>,
        status: <span class="hljs-string">'paid'</span>,
        email: <span class="hljs-string">'jack@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'mastercard'</span>
    },
    {
        id: <span class="hljs-string">'2'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-2.png'</span>,
        avatarFallback: <span class="hljs-string">'MG'</span>,
        name: <span class="hljs-string">'Maria Gonzalez'</span>,
        amount: <span class="hljs-number">253.4</span>,
        status: <span class="hljs-string">'pending'</span>,
        email: <span class="hljs-string">'maria.g@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'visa'</span>
    },
    {
        id: <span class="hljs-string">'3'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-3.png'</span>,
        avatarFallback: <span class="hljs-string">'JD'</span>,
        name: <span class="hljs-string">'John Doe'</span>,
        amount: <span class="hljs-number">852.0</span>,
        status: <span class="hljs-string">'paid'</span>,
        email: <span class="hljs-string">'john.doe@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'mastercard'</span>
    },
    {
        id: <span class="hljs-string">'4'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-4.png'</span>,
        avatarFallback: <span class="hljs-string">'EC'</span>,
        name: <span class="hljs-string">'Emily Carter'</span>,
        amount: <span class="hljs-number">889.0</span>,
        status: <span class="hljs-string">'pending'</span>,
        email: <span class="hljs-string">'emily.carter@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'visa'</span>
    },
    {
        id: <span class="hljs-string">'5'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-5.png'</span>,
        avatarFallback: <span class="hljs-string">'DL'</span>,
        name: <span class="hljs-string">'David Lee'</span>,
        amount: <span class="hljs-number">723.16</span>,
        status: <span class="hljs-string">'paid'</span>,
        email: <span class="hljs-string">'david.lee@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'mastercard'</span>
    },
    {
        id: <span class="hljs-string">'6'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-6.png'</span>,
        avatarFallback: <span class="hljs-string">'SP'</span>,
        name: <span class="hljs-string">'Sophia Patel'</span>,
        amount: <span class="hljs-number">612.0</span>,
        status: <span class="hljs-string">'failed'</span>,
        email: <span class="hljs-string">'sophia.patel@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'mastercard'</span>
    },
    {
        id: <span class="hljs-string">'7'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-7.png'</span>,
        avatarFallback: <span class="hljs-string">'RW'</span>,
        name: <span class="hljs-string">'Robert Wilson'</span>,
        amount: <span class="hljs-number">445.25</span>,
        status: <span class="hljs-string">'paid'</span>,
        email: <span class="hljs-string">'robert.wilson@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'visa'</span>
    },
    {
        id: <span class="hljs-string">'8'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-8.png'</span>,
        avatarFallback: <span class="hljs-string">'LM'</span>,
        name: <span class="hljs-string">'Lisa Martinez'</span>,
        amount: <span class="hljs-number">297.8</span>,
        status: <span class="hljs-string">'processing'</span>,
        email: <span class="hljs-string">'lisa.martinez@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'mastercard'</span>
    },
    {
        id: <span class="hljs-string">'9'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-9.png'</span>,
        avatarFallback: <span class="hljs-string">'MT'</span>,
        name: <span class="hljs-string">'Michael Thompson'</span>,
        amount: <span class="hljs-number">756.9</span>,
        status: <span class="hljs-string">'paid'</span>,
        email: <span class="hljs-string">'michael.thompson@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'visa'</span>
    },
    {
        id: <span class="hljs-string">'10'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-10.png'</span>,
        avatarFallback: <span class="hljs-string">'AJ'</span>,
        name: <span class="hljs-string">'Amanda Johnson'</span>,
        amount: <span class="hljs-number">189.5</span>,
        status: <span class="hljs-string">'pending'</span>,
        email: <span class="hljs-string">'amanda.johnson@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'mastercard'</span>
    },
    {
        id: <span class="hljs-string">'11'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-11.png'</span>,
        avatarFallback: <span class="hljs-string">'KB'</span>,
        name: <span class="hljs-string">'Kevin Brown'</span>,
        amount: <span class="hljs-number">1024.75</span>,
        status: <span class="hljs-string">'paid'</span>,
        email: <span class="hljs-string">'kevin.brown@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'visa'</span>
    },
    {
        id: <span class="hljs-string">'12'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-12.png'</span>,
        avatarFallback: <span class="hljs-string">'SD'</span>,
        name: <span class="hljs-string">'Sarah Davis'</span>,
        amount: <span class="hljs-number">367.2</span>,
        status: <span class="hljs-string">'failed'</span>,
        email: <span class="hljs-string">'sarah.davis@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'mastercard'</span>
    },
    {
        id: <span class="hljs-string">'13'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-13.png'</span>,
        avatarFallback: <span class="hljs-string">'CG'</span>,
        name: <span class="hljs-string">'Christopher Garcia'</span>,
        amount: <span class="hljs-number">598.45</span>,
        status: <span class="hljs-string">'processing'</span>,
        email: <span class="hljs-string">'christopher.garcia@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'visa'</span>
    },
    {
        id: <span class="hljs-string">'14'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-14.png'</span>,
        avatarFallback: <span class="hljs-string">'JR'</span>,
        name: <span class="hljs-string">'Jennifer Rodriguez'</span>,
        amount: <span class="hljs-number">821.3</span>,
        status: <span class="hljs-string">'paid'</span>,
        email: <span class="hljs-string">'jennifer.rodriguez@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'mastercard'</span>
    },
    {
        id: <span class="hljs-string">'15'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-15.png'</span>,
        avatarFallback: <span class="hljs-string">'DM'</span>,
        name: <span class="hljs-string">'Daniel Miller'</span>,
        amount: <span class="hljs-number">156.75</span>,
        status: <span class="hljs-string">'pending'</span>,
        email: <span class="hljs-string">'daniel.miller@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'visa'</span>
    },
    {
        id: <span class="hljs-string">'16'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-16.png'</span>,
        avatarFallback: <span class="hljs-string">'NW'</span>,
        name: <span class="hljs-string">'Nicole White'</span>,
        amount: <span class="hljs-number">934.1</span>,
        status: <span class="hljs-string">'paid'</span>,
        email: <span class="hljs-string">'nicole.white@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'mastercard'</span>
    },
    {
        id: <span class="hljs-string">'17'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-17.png'</span>,
        avatarFallback: <span class="hljs-string">'AL'</span>,
        name: <span class="hljs-string">'Anthony Lopez'</span>,
        amount: <span class="hljs-number">412.85</span>,
        status: <span class="hljs-string">'failed'</span>,
        email: <span class="hljs-string">'anthony.lopez@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'visa'</span>
    },
    {
        id: <span class="hljs-string">'18'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-18.png'</span>,
        avatarFallback: <span class="hljs-string">'MH'</span>,
        name: <span class="hljs-string">'Michelle Harris'</span>,
        amount: <span class="hljs-number">675.5</span>,
        status: <span class="hljs-string">'processing'</span>,
        email: <span class="hljs-string">'michelle.harris@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'mastercard'</span>
    },
    {
        id: <span class="hljs-string">'19'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-19.png'</span>,
        avatarFallback: <span class="hljs-string">'JC'</span>,
        name: <span class="hljs-string">'James Clark'</span>,
        amount: <span class="hljs-number">289.95</span>,
        status: <span class="hljs-string">'paid'</span>,
        email: <span class="hljs-string">'james.clark@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'visa'</span>
    },
    {
        id: <span class="hljs-string">'20'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-20.png'</span>,
        avatarFallback: <span class="hljs-string">'RL'</span>,
        name: <span class="hljs-string">'Rachel Lewis'</span>,
        amount: <span class="hljs-number">1156.25</span>,
        status: <span class="hljs-string">'pending'</span>,
        email: <span class="hljs-string">'rachel.lewis@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'mastercard'</span>
    },
    {
        id: <span class="hljs-string">'21'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-21.png'</span>,
        avatarFallback: <span class="hljs-string">'TY'</span>,
        name: <span class="hljs-string">'Thomas Young'</span>,
        amount: <span class="hljs-number">543.6</span>,
        status: <span class="hljs-string">'paid'</span>,
        email: <span class="hljs-string">'thomas.young@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'visa'</span>
    },
    {
        id: <span class="hljs-string">'22'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-22.png'</span>,
        avatarFallback: <span class="hljs-string">'SB'</span>,
        name: <span class="hljs-string">'Stephanie Brown'</span>,
        amount: <span class="hljs-number">789.3</span>,
        status: <span class="hljs-string">'processing'</span>,
        email: <span class="hljs-string">'stephanie.brown@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'mastercard'</span>
    },
    {
        id: <span class="hljs-string">'23'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-23.png'</span>,
        avatarFallback: <span class="hljs-string">'BM'</span>,
        name: <span class="hljs-string">'Brandon Moore'</span>,
        amount: <span class="hljs-number">425.75</span>,
        status: <span class="hljs-string">'failed'</span>,
        email: <span class="hljs-string">'brandon.moore@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'visa'</span>
    },
    {
        id: <span class="hljs-string">'24'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-24.png'</span>,
        avatarFallback: <span class="hljs-string">'KT'</span>,
        name: <span class="hljs-string">'Kelly Taylor'</span>,
        amount: <span class="hljs-number">1203.5</span>,
        status: <span class="hljs-string">'paid'</span>,
        email: <span class="hljs-string">'kelly.taylor@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'mastercard'</span>
    },
    {
        id: <span class="hljs-string">'25'</span>,
        avatar: <span class="hljs-string">'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-25.png'</span>,
        avatarFallback: <span class="hljs-string">'MA'</span>,
        name: <span class="hljs-string">'Mark Anderson'</span>,
        amount: <span class="hljs-number">356.2</span>,
        status: <span class="hljs-string">'pending'</span>,
        email: <span class="hljs-string">'mark.anderson@shadcnstudio.com'</span>,
        paidBy: <span class="hljs-string">'visa'</span>
    }
]

<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> Route = createFileRoute(<span class="hljs-string">'/dashboard/'</span>)({
    component: RouteComponent,
})

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">RouteComponent</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">return</span> (
        &lt;div className=<span class="hljs-string">'grid grid-cols-2 gap-6 lg:grid-cols-3'</span>&gt;
            {<span class="hljs-comment">/* Statistics Cards */</span>}
            &lt;div className=<span class="hljs-string">'col-span-full grid gap-6 sm:grid-cols-3 md:max-lg:grid-cols-1'</span>&gt;
                {StatisticsCardData.map(<span class="hljs-function">(<span class="hljs-params">card, index</span>) =&gt;</span> (
                    &lt;StatisticsCard
                        key={index}
                        icon={card.icon}
                        title={card.title}
                        value={card.value}
                        changePercentage={card.changePercentage}
                    /&gt;
                ))}
            &lt;/div&gt;

            &lt;div className=<span class="hljs-string">'grid gap-6 max-xl:col-span-full lg:max-xl:grid-cols-2'</span>&gt;
                {<span class="hljs-comment">/* Product Insights Card */</span>}
                &lt;ProductInsightsCard className=<span class="hljs-string">'justify-between gap-3 *:data-[slot=card-content]:space-y-5'</span> /&gt;

                {<span class="hljs-comment">/* Total Earning Card */</span>}
                &lt;TotalEarningCard
                    title=<span class="hljs-string">'Total Earning'</span>
                    earning={<span class="hljs-number">24650</span>}
                    trend=<span class="hljs-string">'up'</span>
                    percentage={<span class="hljs-number">10</span>}
                    comparisonText=<span class="hljs-string">'Compare to last year ($84,325)'</span>
                    earningData={earningData}
                    className=<span class="hljs-string">'justify-between gap-5 sm:min-w-0 *:data-[slot=card-content]:space-y-7'</span>
                /&gt;
            &lt;/div&gt;

            &lt;SalesMetricsCard className=<span class="hljs-string">'col-span-full xl:col-span-2 *:data-[slot=card-content]:space-y-6'</span> /&gt;
            &lt;Card className=<span class="hljs-string">'col-span-full w-full py-0'</span>&gt;
                &lt;TransactionDatatable data={transactionData} /&gt;
            &lt;/Card&gt;
        &lt;/div&gt;
    )
}
</code></pre>
<p>Our dashboard homepage uses various shadcn-studio blocks like:</p>
<ul>
<li><p><strong>Statistics cards</strong> display KPIs (Shipped Orders, Damaged Returns, and so on) with trend indicators. Each card receives props for the icon, value, title, and percentage change, making them reusable for any metric.</p>
</li>
<li><p><strong>Chart components</strong> like <code>&lt;SalesMetricsCard&gt;</code> use <code>recharts</code> under the hood to visualize data. The styling comes from shadcn/ui's card component and Tailwind utilities.</p>
</li>
<li><p><strong>Transaction data table</strong> demonstrates TanStack Table integration. We pass an array of transaction objects, and the <code>&lt;TransactionDatatable&gt;</code> component handles rendering, sorting, and pagination. Notice how we use TypeScript's <code>Item[]</code> type for full type safety.</p>
</li>
</ul>
<p>If you now navigate to <code>/dashboard</code>, you should see an admin dashboard with KPI statistics, charts, a dashboard, and a transaction table. Here is what it would look like:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1764747793227/ca1c0e10-e295-45c4-8e3c-15702583c887.jpeg" alt="tanstack start dashboard demo" class="image--center mx-auto" width="1454" height="1388" loading="lazy"></p>
<p>We have built this beautiful dashboard quickly by using the shadcn/studio’s pre-built blocks.</p>
<h3 id="heading-7-set-up-the-products-page">7. Set up the Products Page.</h3>
<p>Before building our products table, we need to install <strong>Zod</strong>, a TypeScript-first schema validation library. We'll use it to validate the data structure of requests to our server function.</p>
<h4 id="heading-why-zod">Why Zod?</h4>
<p>TanStack Start's server functions use Zod to ensure type-safe data transfer between client and server. When we request to fetch products, Zod validates that the request includes the correct types for <code>page</code>, <code>pageSize</code>, <code>sortBy</code>, and <code>filters</code>. This catches errors at runtime and provides excellent TypeScript inference.</p>
<p>Now, let’s set up the products page with a products table. But before that, let’s install the zod package dependency. Here is the command for it:</p>
<pre><code class="lang-bash">pnpm add zod
</code></pre>
<h4 id="heading-creating-mock-product-data">Creating Mock Product Data</h4>
<p>We will need to store our mock products’ data somewhere. For that, we will create a new file <code>data/products.ts</code> and paste the code below. This will help us mock the product data for our products table.</p>
<pre><code class="lang-typescript"><span class="hljs-keyword">import</span> { createServerFn } <span class="hljs-keyword">from</span> <span class="hljs-string">"@tanstack/react-start"</span>;
<span class="hljs-keyword">import</span> { z } <span class="hljs-keyword">from</span> <span class="hljs-string">"zod"</span>;

<span class="hljs-keyword">export</span> <span class="hljs-keyword">type</span> Product = {
    id: <span class="hljs-built_in">string</span>
    name: <span class="hljs-built_in">string</span>
    category: <span class="hljs-built_in">string</span>
    price: <span class="hljs-built_in">number</span>
    stock: <span class="hljs-built_in">number</span>
    status: <span class="hljs-string">'active'</span> | <span class="hljs-string">'draft'</span> | <span class="hljs-string">'archived'</span>
    image: <span class="hljs-built_in">string</span>
}

<span class="hljs-comment">// Define the type for the data parameter</span>
<span class="hljs-keyword">type</span> ProductQueryParams = {
    page: <span class="hljs-built_in">number</span>;
    pageSize: <span class="hljs-built_in">number</span>;
    sortBy?: <span class="hljs-built_in">string</span>;
    sortOrder?: <span class="hljs-string">"asc"</span> | <span class="hljs-string">"desc"</span>;
    filters?: {
        name?: <span class="hljs-built_in">string</span>;
        category?: <span class="hljs-built_in">string</span>;
        status?: <span class="hljs-built_in">string</span>;
    };
};

<span class="hljs-keyword">const</span> products: Product[] = [
    {
        id: <span class="hljs-string">'PROD-001'</span>,
        name: <span class="hljs-string">'Wireless Noise Cancelling Headphones'</span>,
        category: <span class="hljs-string">'Electronics'</span>,
        price: <span class="hljs-number">299.99</span>,
        stock: <span class="hljs-number">45</span>,
        status: <span class="hljs-string">'active'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1505740420928-5e560c06d30e?w=100&amp;q=80'</span>,
    },
    {
        id: <span class="hljs-string">'PROD-002'</span>,
        name: <span class="hljs-string">'Ergonomic Office Chair'</span>,
        category: <span class="hljs-string">'Furniture'</span>,
        price: <span class="hljs-number">199.50</span>,
        stock: <span class="hljs-number">12</span>,
        status: <span class="hljs-string">'active'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1592078615290-033ee584e267?w=100&amp;q=80'</span>,
    },
    {
        id: <span class="hljs-string">'PROD-003'</span>,
        name: <span class="hljs-string">'Mechanical Gaming Keyboard'</span>,
        category: <span class="hljs-string">'Electronics'</span>,
        price: <span class="hljs-number">129.99</span>,
        stock: <span class="hljs-number">0</span>,
        status: <span class="hljs-string">'archived'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1587829741301-dc798b91add1?w=100&amp;q=80'</span>,
    },
    {
        id: <span class="hljs-string">'PROD-004'</span>,
        name: <span class="hljs-string">'Smart Fitness Watch'</span>,
        category: <span class="hljs-string">'Wearables'</span>,
        price: <span class="hljs-number">149.00</span>,
        stock: <span class="hljs-number">89</span>,
        status: <span class="hljs-string">'active'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1523275335684-37898b6baf30?w=100&amp;q=80'</span>,
    },
    {
        id: <span class="hljs-string">'PROD-005'</span>,
        name: <span class="hljs-string">'Minimalist Desk Lamp'</span>,
        category: <span class="hljs-string">'Lighting'</span>,
        price: <span class="hljs-number">45.00</span>,
        stock: <span class="hljs-number">23</span>,
        status: <span class="hljs-string">'draft'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1507473888900-52e1ad14723b?w=100&amp;q=80'</span>,
    },
    {
        id: <span class="hljs-string">'PROD-006'</span>,
        name: <span class="hljs-string">'Portable Bluetooth Speaker'</span>,
        category: <span class="hljs-string">'Electronics'</span>,
        price: <span class="hljs-number">79.99</span>,
        stock: <span class="hljs-number">150</span>,
        status: <span class="hljs-string">'active'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1608043152269-423dbba4e7e1?w=100&amp;q=80'</span>,
    },
    {
        id: <span class="hljs-string">'PROD-007'</span>,
        name: <span class="hljs-string">'Ceramic Coffee Mug Set'</span>,
        category: <span class="hljs-string">'Kitchen'</span>,
        price: <span class="hljs-number">24.99</span>,
        stock: <span class="hljs-number">200</span>,
        status: <span class="hljs-string">'active'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1514228742587-6b1558fcca3d?w=100&amp;q=80'</span>,
    },
    {
        id: <span class="hljs-string">'PROD-008'</span>,
        name: <span class="hljs-string">'Leather Messenger Bag'</span>,
        category: <span class="hljs-string">'Accessories'</span>,
        price: <span class="hljs-number">129.50</span>,
        stock: <span class="hljs-number">15</span>,
        status: <span class="hljs-string">'active'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1553062407-98eeb64c6a62?w=100&amp;q=80'</span>,
    },
    {
        id: <span class="hljs-string">'PROD-009'</span>,
        name: <span class="hljs-string">'Wireless Charging Pad'</span>,
        category: <span class="hljs-string">'Electronics'</span>,
        price: <span class="hljs-number">39.99</span>,
        stock: <span class="hljs-number">75</span>,
        status: <span class="hljs-string">'active'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1586816879360-004f5b0c51e3?w=100&amp;q=80'</span>,
    },
    {
        id: <span class="hljs-string">'PROD-010'</span>,
        name: <span class="hljs-string">'Succulent Plant Set'</span>,
        category: <span class="hljs-string">'Home &amp; Garden'</span>,
        price: <span class="hljs-number">29.99</span>,
        stock: <span class="hljs-number">30</span>,
        status: <span class="hljs-string">'active'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1485955900006-10f4d324d411?w=100&amp;q=80'</span>,
    },
    {
        id: <span class="hljs-string">'PROD-011'</span>,
        name: <span class="hljs-string">'Professional Chef Knife'</span>,
        category: <span class="hljs-string">'Kitchen'</span>,
        price: <span class="hljs-number">89.95</span>,
        stock: <span class="hljs-number">42</span>,
        status: <span class="hljs-string">'active'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1593618998160-e34014e67546?w=100&amp;q=80'</span>,
    },
    {
        id: <span class="hljs-string">'PROD-012'</span>,
        name: <span class="hljs-string">'Yoga Mat'</span>,
        category: <span class="hljs-string">'Fitness'</span>,
        price: <span class="hljs-number">35.00</span>,
        stock: <span class="hljs-number">100</span>,
        status: <span class="hljs-string">'active'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1601925260368-ae2f83cf8b7f?w=100&amp;q=80'</span>,
    },
    {
        id: <span class="hljs-string">'PROD-013'</span>,
        name: <span class="hljs-string">'Smart Thermostat'</span>,
        category: <span class="hljs-string">'Home Automation'</span>,
        price: <span class="hljs-number">199.00</span>,
        stock: <span class="hljs-number">0</span>,
        status: <span class="hljs-string">'archived'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1567789884554-0b844b597180?w=100&amp;q=80'</span>,
    },
    {
        id: <span class="hljs-string">'PROD-014'</span>,
        name: <span class="hljs-string">'Vintage Film Camera'</span>,
        category: <span class="hljs-string">'Photography'</span>,
        price: <span class="hljs-number">450.00</span>,
        stock: <span class="hljs-number">3</span>,
        status: <span class="hljs-string">'draft'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1526170375885-4d8ecf77b99f?w=100&amp;q=80'</span>,
    },
    {
        id: <span class="hljs-string">'PROD-015'</span>,
        name: <span class="hljs-string">'Cotton T-Shirt Pack'</span>,
        category: <span class="hljs-string">'Apparel'</span>,
        price: <span class="hljs-number">49.99</span>,
        stock: <span class="hljs-number">150</span>,
        status: <span class="hljs-string">'active'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1521572163474-6864f9cf17ab?w=100&amp;q=80'</span>,
    },
    {
        id: <span class="hljs-string">'PROD-016'</span>,
        name: <span class="hljs-string">'Electric Toothbrush'</span>,
        category: <span class="hljs-string">'Personal Care'</span>,
        price: <span class="hljs-number">69.99</span>,
        stock: <span class="hljs-number">55</span>,
        status: <span class="hljs-string">'active'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1559656914-a30970c1affd?w=100&amp;q=80'</span>,
    },
    {
        id: <span class="hljs-string">'PROD-017'</span>,
        name: <span class="hljs-string">'Gaming Mouse'</span>,
        category: <span class="hljs-string">'Electronics'</span>,
        price: <span class="hljs-number">59.99</span>,
        stock: <span class="hljs-number">88</span>,
        status: <span class="hljs-string">'active'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1527864550417-7fd91fc51a46?w=100&amp;q=80'</span>,
    },
    {
        id: <span class="hljs-string">'PROD-018'</span>,
        name: <span class="hljs-string">'Essential Oil Diffuser'</span>,
        category: <span class="hljs-string">'Home &amp; Garden'</span>,
        price: <span class="hljs-number">34.50</span>,
        stock: <span class="hljs-number">25</span>,
        status: <span class="hljs-string">'active'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1602928321679-560bb453f190?w=100&amp;q=80'</span>,
    },
    {
        id: <span class="hljs-string">'PROD-019'</span>,
        name: <span class="hljs-string">'Running Shoes'</span>,
        category: <span class="hljs-string">'Footwear'</span>,
        price: <span class="hljs-number">119.99</span>,
        stock: <span class="hljs-number">60</span>,
        status: <span class="hljs-string">'active'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1542291026-7eec264c27ff?w=100&amp;q=80'</span>,
    },
    {
        id: <span class="hljs-string">'PROD-020'</span>,
        name: <span class="hljs-string">'Digital Drawing Tablet'</span>,
        category: <span class="hljs-string">'Electronics'</span>,
        price: <span class="hljs-number">249.00</span>,
        stock: <span class="hljs-number">18</span>,
        status: <span class="hljs-string">'active'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1561525140-c2a4cc68e4bd?w=100&amp;q=80'</span>,
    },
    {
        id: <span class="hljs-string">'PROD-021'</span>,
        name: <span class="hljs-string">'Bamboo Cutting Board'</span>,
        category: <span class="hljs-string">'Kitchen'</span>,
        price: <span class="hljs-number">22.99</span>,
        stock: <span class="hljs-number">95</span>,
        status: <span class="hljs-string">'active'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1594385208974-2e75f8d7bb48?w=100&amp;q=80'</span>,
    },
    {
        id: <span class="hljs-string">'PROD-022'</span>,
        name: <span class="hljs-string">'Sunglasses'</span>,
        category: <span class="hljs-string">'Accessories'</span>,
        price: <span class="hljs-number">159.00</span>,
        stock: <span class="hljs-number">40</span>,
        status: <span class="hljs-string">'active'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1511499767150-a48a237f0083?w=100&amp;q=80'</span>,
    },
    {
        id: <span class="hljs-string">'PROD-023'</span>,
        name: <span class="hljs-string">'Water Bottle'</span>,
        category: <span class="hljs-string">'Fitness'</span>,
        price: <span class="hljs-number">19.99</span>,
        stock: <span class="hljs-number">300</span>,
        status: <span class="hljs-string">'active'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1602143407151-01114192003f?w=100&amp;q=80'</span>,
    },
    {
        id: <span class="hljs-string">'PROD-024'</span>,
        name: <span class="hljs-string">'Throw Pillow Set'</span>,
        category: <span class="hljs-string">'Home Decor'</span>,
        price: <span class="hljs-number">45.99</span>,
        stock: <span class="hljs-number">28</span>,
        status: <span class="hljs-string">'active'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1584100936595-c0654b55a2e6?w=100&amp;q=80'</span>,
    },
    {
        id: <span class="hljs-string">'PROD-025'</span>,
        name: <span class="hljs-string">'Wireless Earbuds'</span>,
        category: <span class="hljs-string">'Electronics'</span>,
        price: <span class="hljs-number">89.99</span>,
        stock: <span class="hljs-number">120</span>,
        status: <span class="hljs-string">'active'</span>,
        image: <span class="hljs-string">'https://images.unsplash.com/photo-1590658268037-6bf12165a8df?w=100&amp;q=80'</span>,
    }
]

<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> getProducts = createServerFn({ method: <span class="hljs-string">"GET"</span> })
    .inputValidator(
        z.object({
            page: z.number().default(<span class="hljs-number">0</span>),
            pageSize: z.number().default(<span class="hljs-number">10</span>),
            sortBy: z.string().optional(),
            sortOrder: z.enum([<span class="hljs-string">"asc"</span>, <span class="hljs-string">"desc"</span>]).optional(),
            filters: z
                .object({
                    name: z.string().optional(),
                    category: z.string().optional(),
                    status: z.string().optional(),
                })
                .optional(),
        })
    )
    .handler(<span class="hljs-keyword">async</span> ({ data }: { data: ProductQueryParams }) =&gt; {
        <span class="hljs-keyword">const</span> { page, pageSize, sortBy, sortOrder, filters } = data;

        <span class="hljs-comment">// Apply filters</span>
        <span class="hljs-keyword">let</span> filteredProducts = [...products];

        <span class="hljs-keyword">if</span> (filters) {
            <span class="hljs-keyword">if</span> (filters.name) {
                filteredProducts = filteredProducts.filter(<span class="hljs-function">(<span class="hljs-params">product</span>) =&gt;</span>
                    product.name.toLowerCase().includes(filters.name!.toLowerCase())
                );
            }

            <span class="hljs-keyword">if</span> (filters.category) {
                filteredProducts = filteredProducts.filter(
                    <span class="hljs-function">(<span class="hljs-params">product</span>) =&gt;</span>
                        product.category.toLowerCase() === filters.category!.toLowerCase()
                );
            }

            <span class="hljs-keyword">if</span> (filters.status) {
                filteredProducts = filteredProducts.filter(
                    <span class="hljs-function">(<span class="hljs-params">product</span>) =&gt;</span> product.status === filters.status
                );
            }
        }

        <span class="hljs-comment">// Apply sorting</span>
        <span class="hljs-keyword">if</span> (sortBy) {
            filteredProducts.sort(<span class="hljs-function">(<span class="hljs-params">a, b</span>) =&gt;</span> {
                <span class="hljs-keyword">const</span> aValue = a[sortBy <span class="hljs-keyword">as</span> keyof Product];
                <span class="hljs-keyword">const</span> bValue = b[sortBy <span class="hljs-keyword">as</span> keyof Product];

                <span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> aValue === <span class="hljs-string">"string"</span> &amp;&amp; <span class="hljs-keyword">typeof</span> bValue === <span class="hljs-string">"string"</span>) {
                    <span class="hljs-keyword">return</span> sortOrder === <span class="hljs-string">"desc"</span>
                        ? bValue.localeCompare(aValue)
                        : aValue.localeCompare(bValue);
                }

                <span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> aValue === <span class="hljs-string">"number"</span> &amp;&amp; <span class="hljs-keyword">typeof</span> bValue === <span class="hljs-string">"number"</span>) {
                    <span class="hljs-keyword">return</span> sortOrder === <span class="hljs-string">"desc"</span> ? bValue - aValue : aValue - bValue;
                }

                <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>;
            });
        }

        <span class="hljs-comment">// Calculate pagination</span>
        <span class="hljs-keyword">const</span> totalCount = filteredProducts.length;
        <span class="hljs-keyword">const</span> totalPages = <span class="hljs-built_in">Math</span>.ceil(totalCount / pageSize);
        <span class="hljs-keyword">const</span> paginatedProducts = filteredProducts.slice(
            page * pageSize,
            (page + <span class="hljs-number">1</span>) * pageSize
        );

        <span class="hljs-comment">// Simulate network delay</span>
        <span class="hljs-keyword">await</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>(<span class="hljs-function">(<span class="hljs-params">resolve</span>) =&gt;</span> <span class="hljs-built_in">setTimeout</span>(resolve, <span class="hljs-number">500</span>));

        <span class="hljs-keyword">return</span> {
            products: paginatedProducts,
            pagination: {
                page,
                pageSize,
                totalCount,
                totalPages,
            },
        };
    });
</code></pre>
<p>Let’s understand the server function and break down what's happening in <code>getProducts</code>:</p>
<ul>
<li><p><strong>Input validation</strong>: The <code>.inputValidator()</code> method uses a Zod schema to validate incoming requests. It ensures <code>page</code> and <code>pageSize</code> are numbers, <code>sortOrder</code> is either "asc" or "desc", and filters are optional strings.</p>
</li>
<li><p><strong>Filtering products</strong>: The function filters the products array based on the provided filters (name, category, status). This simulates what a real database query would do.</p>
</li>
<li><p><strong>Sorting</strong>: Products are sorted by the specified column (<code>sortBy</code>) in ascending or descending order (<code>sortOrder</code>).</p>
</li>
<li><p><strong>Pagination</strong>: We calculate which slice of products to return based on <code>page</code> and <code>pageSize</code>, along with metadata like <code>totalCount</code> and <code>totalPages</code>.</p>
</li>
</ul>
<h4 id="heading-create-the-products-table">Create the Products table:</h4>
<p>Once the data is done, let’s create a table in <code>/dashboard/products.tsx</code>. This table will use our mock product data and will provide multiple functions in the table, like search, sort, and filter. This table demonstrates the powerful combination of TanStack Query for data management and TanStack Table for rendering.</p>
<p>Paste the code below in the <code>products.tsx</code> file:</p>
<pre><code class="lang-bash">import { useQuery } from <span class="hljs-string">'@tanstack/react-query'</span>
import { createFileRoute } from <span class="hljs-string">'@tanstack/react-router'</span>
import {
    ColumnDef,
    ColumnFiltersState,
    flexRender,
    getCoreRowModel,
    getFilteredRowModel,
    getPaginationRowModel,
    getSortedRowModel,
    SortingState,
    useReactTable,
    VisibilityState,
} from <span class="hljs-string">'@tanstack/react-table'</span>
import {
    ArrowUpDown,
    ChevronDown,
    Filter,
    Loader2,
    MoreHorizontal,
    Plus,
    Search
} from <span class="hljs-string">'lucide-react'</span>
import { useState } from <span class="hljs-string">'react'</span>

import { Badge } from <span class="hljs-string">'@/components/ui/badge'</span>
import { Button } from <span class="hljs-string">'@/components/ui/button'</span>
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from <span class="hljs-string">'@/components/ui/card'</span>
import {
    DropdownMenu,
    DropdownMenuCheckboxItem,
    DropdownMenuContent,
    DropdownMenuItem,
    DropdownMenuLabel,
    DropdownMenuSeparator,
    DropdownMenuTrigger,
} from <span class="hljs-string">'@/components/ui/dropdown-menu'</span>
import { Input } from <span class="hljs-string">'@/components/ui/input'</span>
import {
    Table,
    TableBody,
    TableCell,
    TableHead,
    TableHeader,
    TableRow,
} from <span class="hljs-string">'@/components/ui/table'</span>
import { getProducts, <span class="hljs-built_in">type</span> Product } from <span class="hljs-string">'@/data/products'</span>

<span class="hljs-built_in">export</span> const Route = createFileRoute(<span class="hljs-string">'/dashboard/products'</span>)({
    component: ProductsPage,
})

<span class="hljs-built_in">export</span> const columns: ColumnDef&lt;Product&gt;[] = [
    {
        accessorKey: <span class="hljs-string">'name'</span>,
        header: ({ column }) =&gt; {
            <span class="hljs-built_in">return</span> (
                &lt;Button
                    variant=<span class="hljs-string">"ghost"</span>
                    onClick={() =&gt; column.toggleSorting(column.getIsSorted() === <span class="hljs-string">"asc"</span>)}
                &gt;
                    Product Name
                    &lt;ArrowUpDown className=<span class="hljs-string">"ml-2 h-4 w-4"</span> /&gt;
                &lt;/Button&gt;
            )
        },
        cell: ({ row }) =&gt; (
            &lt;div className=<span class="hljs-string">"flex items-center gap-3"</span>&gt;
                &lt;img
                    src={row.original.image}
                    alt={row.getValue(<span class="hljs-string">'name'</span>)}
                    className=<span class="hljs-string">"h-10 w-10 rounded-md object-cover"</span>
                /&gt;
                &lt;div className=<span class="hljs-string">"flex flex-col"</span>&gt;
                    &lt;span className=<span class="hljs-string">"font-medium"</span>&gt;{row.getValue(<span class="hljs-string">'name'</span>)}&lt;/span&gt;
                    &lt;span className=<span class="hljs-string">"text-xs text-muted-foreground"</span>&gt;{row.original.id}&lt;/span&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        ),
    },
    {
        accessorKey: <span class="hljs-string">'category'</span>,
        header: <span class="hljs-string">'Category'</span>,
        cell: ({ row }) =&gt; &lt;div&gt;{row.getValue(<span class="hljs-string">'category'</span>)}&lt;/div&gt;,
    },
    {
        accessorKey: <span class="hljs-string">'status'</span>,
        header: <span class="hljs-string">'Status'</span>,
        cell: ({ row }) =&gt; {
            const status = row.getValue(<span class="hljs-string">'status'</span>) as string
            <span class="hljs-built_in">return</span> (
                &lt;Badge variant={status === <span class="hljs-string">'active'</span> ? <span class="hljs-string">'default'</span> : status === <span class="hljs-string">'draft'</span> ? <span class="hljs-string">'secondary'</span> : <span class="hljs-string">'outline'</span>}&gt;
                    {status}
                &lt;/Badge&gt;
            )
        },
    },
    {
        accessorKey: <span class="hljs-string">'price'</span>,
        header: () =&gt; &lt;div className=<span class="hljs-string">"text-right"</span>&gt;Price&lt;/div&gt;,
        cell: ({ row }) =&gt; {
            const amount = parseFloat(row.getValue(<span class="hljs-string">'price'</span>))
            const formatted = new Intl.NumberFormat(<span class="hljs-string">'en-US'</span>, {
                style: <span class="hljs-string">'currency'</span>,
                currency: <span class="hljs-string">'USD'</span>,
            }).format(amount)

            <span class="hljs-built_in">return</span> &lt;div className=<span class="hljs-string">"text-right font-medium"</span>&gt;{formatted}&lt;/div&gt;
        },
    },
    {
        accessorKey: <span class="hljs-string">'stock'</span>,
        header: () =&gt; &lt;div className=<span class="hljs-string">"text-right"</span>&gt;Stock&lt;/div&gt;,
        cell: ({ row }) =&gt; {
            const stock = parseFloat(row.getValue(<span class="hljs-string">'stock'</span>))
            <span class="hljs-built_in">return</span> &lt;div className={`text-right <span class="hljs-variable">${stock === 0 ? 'text-red-500 font-medium' : ''}</span>`}&gt;{stock}&lt;/div&gt;
        },
    },
    {
        id: <span class="hljs-string">'actions'</span>,
        enableHiding: <span class="hljs-literal">false</span>,
        cell: ({ row }) =&gt; {
            const product = row.original

            <span class="hljs-built_in">return</span> (
                &lt;DropdownMenu&gt;
                    &lt;DropdownMenuTrigger asChild&gt;
                        &lt;Button variant=<span class="hljs-string">"ghost"</span> className=<span class="hljs-string">"h-8 w-8 p-0"</span>&gt;
                            &lt;span className=<span class="hljs-string">"sr-only"</span>&gt;Open menu&lt;/span&gt;
                            &lt;MoreHorizontal className=<span class="hljs-string">"h-4 w-4"</span> /&gt;
                        &lt;/Button&gt;
                    &lt;/DropdownMenuTrigger&gt;
                    &lt;DropdownMenuContent align=<span class="hljs-string">"end"</span>&gt;
                        &lt;DropdownMenuLabel&gt;Actions&lt;/DropdownMenuLabel&gt;
                        &lt;DropdownMenuItem
                            onClick={() =&gt; navigator.clipboard.writeText(product.id)}
                        &gt;
                            Copy Product ID
                        &lt;/DropdownMenuItem&gt;
                        &lt;DropdownMenuSeparator /&gt;
                        &lt;DropdownMenuItem&gt;Edit Product&lt;/DropdownMenuItem&gt;
                        &lt;DropdownMenuItem&gt;View Details&lt;/DropdownMenuItem&gt;
                    &lt;/DropdownMenuContent&gt;
                &lt;/DropdownMenu&gt;
            )
        },
    },
]

<span class="hljs-keyword">function</span> <span class="hljs-function"><span class="hljs-title">ProductsPage</span></span>() {
    const [sorting, setSorting] = useState&lt;SortingState&gt;([])
    const [columnFilters, setColumnFilters] = useState&lt;ColumnFiltersState&gt;([])
    const [columnVisibility, setColumnVisibility] = useState&lt;VisibilityState&gt;({})
    const [rowSelection, setRowSelection] = useState({})
    const [pagination, setPagination] = useState({
        pageIndex: 0,
        pageSize: 10,
    })

    const { data, isLoading } = useQuery({
        queryKey: [<span class="hljs-string">'products'</span>, pagination, sorting, columnFilters],
        queryFn: () =&gt; getProducts({
            data: {
                page: pagination.pageIndex,
                pageSize: pagination.pageSize,
                sortBy: sorting[0]?.id,
                sortOrder: sorting[0]?.desc ? <span class="hljs-string">'desc'</span> : <span class="hljs-string">'asc'</span>,
                filters: {
                    name: (columnFilters.find((f) =&gt; f.id === <span class="hljs-string">'name'</span>)?.value as string) || undefined,
                    status: (columnFilters.find((f) =&gt; f.id === <span class="hljs-string">'status'</span>)?.value as string) || undefined,
                }
            }
        }),
    })

    const products = data?.products || []
    const totalPages = data?.pagination.totalPages || 0
    const totalCount = data?.pagination.totalCount || 0

    const table = useReactTable({
        data: products,
        columns,
        pageCount: totalPages,
        manualPagination: <span class="hljs-literal">true</span>,
        manualSorting: <span class="hljs-literal">true</span>,
        manualFiltering: <span class="hljs-literal">true</span>,
        onSortingChange: setSorting,
        onColumnFiltersChange: setColumnFilters,
        getCoreRowModel: getCoreRowModel(),
        getPaginationRowModel: getPaginationRowModel(),
        getSortedRowModel: getSortedRowModel(),
        getFilteredRowModel: getFilteredRowModel(),
        onColumnVisibilityChange: setColumnVisibility,
        onRowSelectionChange: setRowSelection,
        onPaginationChange: setPagination,
        state: {
            sorting,
            columnFilters,
            columnVisibility,
            rowSelection,
            pagination,
        },
    })

    <span class="hljs-built_in">return</span> (
        &lt;div className=<span class="hljs-string">"w-full space-y-4"</span>&gt;
            &lt;div className=<span class="hljs-string">"flex items-center justify-between"</span>&gt;
                &lt;h2 className=<span class="hljs-string">"text-2xl font-bold tracking-tight"</span>&gt;Products&lt;/h2&gt;
                &lt;div className=<span class="hljs-string">"flex items-center gap-2"</span>&gt;
                    &lt;Button variant=<span class="hljs-string">"outline"</span> size=<span class="hljs-string">"sm"</span>&gt;
                        &lt;Filter className=<span class="hljs-string">"mr-2 h-4 w-4"</span> /&gt;
                        Filter
                    &lt;/Button&gt;
                    &lt;Button size=<span class="hljs-string">"sm"</span>&gt;
                        &lt;Plus className=<span class="hljs-string">"mr-2 h-4 w-4"</span> /&gt;
                        Add Product
                    &lt;/Button&gt;
                &lt;/div&gt;
            &lt;/div&gt;

            &lt;Card&gt;
                &lt;CardHeader&gt;
                    &lt;CardTitle&gt;Product Management&lt;/CardTitle&gt;
                    &lt;CardDescription&gt;
                        Manage your product catalog, track inventory, and update prices.
                    &lt;/CardDescription&gt;
                &lt;/CardHeader&gt;
                &lt;CardContent&gt;
                    &lt;div className=<span class="hljs-string">"flex items-center py-4 gap-2"</span>&gt;
                        &lt;div className=<span class="hljs-string">"relative flex-1"</span>&gt;
                            &lt;Search className=<span class="hljs-string">"absolute left-2 top-2.5 h-4 w-4 text-muted-foreground"</span> /&gt;
                            &lt;Input
                                placeholder=<span class="hljs-string">"Filter products..."</span>
                                value={(table.getColumn(<span class="hljs-string">"name"</span>)?.getFilterValue() as string) ?? <span class="hljs-string">""</span>}
                                onChange={(event) =&gt;
                                    table.getColumn(<span class="hljs-string">"name"</span>)?.setFilterValue(event.target.value)
                                }
                                className=<span class="hljs-string">"pl-8 max-w-sm"</span>
                            /&gt;
                        &lt;/div&gt;
                        &lt;DropdownMenu&gt;
                            &lt;DropdownMenuTrigger asChild&gt;
                                &lt;Button variant=<span class="hljs-string">"outline"</span> className=<span class="hljs-string">"ml-auto"</span>&gt;
                                    Columns &lt;ChevronDown className=<span class="hljs-string">"ml-2 h-4 w-4"</span> /&gt;
                                &lt;/Button&gt;
                            &lt;/DropdownMenuTrigger&gt;
                            &lt;DropdownMenuContent align=<span class="hljs-string">"end"</span>&gt;
                                {table
                                    .getAllColumns()
                                    .filter((column) =&gt; column.getCanHide())
                                    .map((column) =&gt; {
                                        <span class="hljs-built_in">return</span> (
                                            &lt;DropdownMenuCheckboxItem
                                                key={column.id}
                                                className=<span class="hljs-string">"capitalize"</span>
                                                checked={column.getIsVisible()}
                                                onCheckedChange={(value) =&gt;
                                                    column.toggleVisibility(!!value)
                                                }
                                            &gt;
                                                {column.id}
                                            &lt;/DropdownMenuCheckboxItem&gt;
                                        )
                                    })}
                            &lt;/DropdownMenuContent&gt;
                        &lt;/DropdownMenu&gt;
                    &lt;/div&gt;
                    &lt;div className=<span class="hljs-string">"rounded-md border"</span>&gt;
                        &lt;Table&gt;
                            &lt;TableHeader&gt;
                                {table.getHeaderGroups().map((headerGroup) =&gt; (
                                    &lt;TableRow key={headerGroup.id}&gt;
                                        {headerGroup.headers.map((header) =&gt; {
                                            <span class="hljs-built_in">return</span> (
                                                &lt;TableHead key={header.id}&gt;
                                                    {header.isPlaceholder
                                                        ? null
                                                        : flexRender(
                                                            header.column.columnDef.header,
                                                            header.getContext()
                                                        )}
                                                &lt;/TableHead&gt;
                                            )
                                        })}
                                    &lt;/TableRow&gt;
                                ))}
                            &lt;/TableHeader&gt;
                            &lt;TableBody&gt;
                                {isLoading ? (
                                    &lt;TableRow&gt;
                                        &lt;TableCell colSpan={columns.length} className=<span class="hljs-string">"h-24 text-center"</span>&gt;
                                            &lt;div className=<span class="hljs-string">"flex items-center justify-center gap-2"</span>&gt;
                                                &lt;Loader2 className=<span class="hljs-string">"h-6 w-6 animate-spin"</span> /&gt;
                                                &lt;span&gt;Loading products...&lt;/span&gt;
                                            &lt;/div&gt;
                                        &lt;/TableCell&gt;
                                    &lt;/TableRow&gt;
                                ) : table.getRowModel().rows?.length ? (
                                    table.getRowModel().rows.map((row) =&gt; (
                                        &lt;TableRow
                                            key={row.id}
                                            data-state={row.getIsSelected() &amp;&amp; <span class="hljs-string">"selected"</span>}
                                        &gt;
                                            {row.getVisibleCells().map((cell) =&gt; (
                                                &lt;TableCell key={cell.id}&gt;
                                                    {flexRender(
                                                        cell.column.columnDef.cell,
                                                        cell.getContext()
                                                    )}
                                                &lt;/TableCell&gt;
                                            ))}
                                        &lt;/TableRow&gt;
                                    ))
                                ) : (
                                    &lt;TableRow&gt;
                                        &lt;TableCell
                                            colSpan={columns.length}
                                            className=<span class="hljs-string">"h-24 text-center"</span>
                                        &gt;
                                            No results.
                                        &lt;/TableCell&gt;
                                    &lt;/TableRow&gt;
                                )}
                            &lt;/TableBody&gt;
                        &lt;/Table&gt;
                    &lt;/div&gt;
                    &lt;div className=<span class="hljs-string">"flex items-center justify-end space-x-2 py-4"</span>&gt;
                        &lt;div className=<span class="hljs-string">"flex-1 text-sm text-muted-foreground"</span>&gt;
                            {table.getFilteredSelectedRowModel().rows.length} of{<span class="hljs-string">" "</span>}
                            {totalCount} row(s) selected.
                        &lt;/div&gt;
                        &lt;div className=<span class="hljs-string">"space-x-2"</span>&gt;
                            &lt;Button
                                variant=<span class="hljs-string">"outline"</span>
                                size=<span class="hljs-string">"sm"</span>
                                onClick={() =&gt; table.previousPage()}
                                disabled={!table.getCanPreviousPage()}
                            &gt;
                                Previous
                            &lt;/Button&gt;
                            &lt;Button
                                variant=<span class="hljs-string">"outline"</span>
                                size=<span class="hljs-string">"sm"</span>
                                onClick={() =&gt; table.nextPage()}
                                disabled={!table.getCanNextPage()}
                            &gt;
                                Next
                            &lt;/Button&gt;
                        &lt;/div&gt;
                    &lt;/div&gt;
                &lt;/CardContent&gt;
            &lt;/Card&gt;
        &lt;/div&gt;
    )
}
</code></pre>
<p>Now you can see the fully functional products page by navigating the <code>/products</code> where you can search and sort the products.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1764748681745/6f73dc04-ac9a-4f75-a1ab-88ed1fc5c6f3.jpeg" alt="tanstack start dashboard demo" class="image--center mx-auto" width="1454" height="1059" loading="lazy"></p>
<h4 id="heading-how-do-tanstack-query-and-tanstack-table-work-in-the-products-table">How do TanStack Query and TanStack Table Work in the products table?</h4>
<p>Our products page uses TanStack Query for data fetching and TanStack Table for rendering.</p>
<p><code>useQuery</code> is a fundamental hook in TanStack Query for managing server state in web applications. It simplifies data fetching, caching, and synchronization.</p>
<p>The below code snippet below shows how we have used useQuery in our product table:</p>
<pre><code class="lang-typescript"><span class="hljs-keyword">import</span> { useQuery } <span class="hljs-keyword">from</span> <span class="hljs-string">'@tanstack/react-query'</span>;

<span class="hljs-keyword">const</span> { data, isLoading } = useQuery({
    queryKey: [<span class="hljs-string">'products'</span>, pagination, sorting, columnFilters],
    queryFn: <span class="hljs-function">() =&gt;</span> getProducts({...})
}
</code></pre>
<p>The <code>useQuery</code> hook manages data fetching in our application. For more details, you can <a target="_blank" href="https://tanstack.com/query/latest">refer to the official docs here</a>.</p>
<p><strong>useReactTable:</strong></p>
<pre><code class="lang-typescript"><span class="hljs-keyword">import</span> { useReactTable } <span class="hljs-keyword">from</span> <span class="hljs-string">'@tanstack/react-table'</span>

<span class="hljs-keyword">const</span> table = useReactTable({
    data: products,
    columns,
    manualPagination: <span class="hljs-literal">true</span>,
    manualSorting: <span class="hljs-literal">true</span>,
    manualFiltering: <span class="hljs-literal">true</span>,
})
</code></pre>
<p><strong>TanStack Table</strong> manages the UI state and rendering. By setting <code>manualPagination</code>, <code>manualSorting</code>, and <code>manualFiltering</code> to <code>true</code>, we tell the table that server-side logic handles these operations.</p>
<p>When users sort, filter, or paginate, the table updates its states, and React Query detects the state change in the <code>queryKey</code>. It refetches data from the server, and the table re-renders with fresh data.</p>
<p>This architecture is production-ready and scales to thousands of rows. You just need to replace the mock API endpoint with your real API endpoint.</p>
<h3 id="heading-8-settings-page">8. Settings Page</h3>
<p>Finally, let’s add a simple Settings page with a profile section and some basic notification preferences.</p>
<p>Below is the code for the Settings Page. You can paste it into <code>/dashboard/settings.tsx</code>:</p>
<pre><code class="lang-bash">import { Avatar, AvatarFallback, AvatarImage } from <span class="hljs-string">'@/components/ui/avatar'</span>
import { Button } from <span class="hljs-string">'@/components/ui/button'</span>
import {
  Card,
  CardContent,
  CardDescription,
  CardFooter,
  CardHeader,
  CardTitle,
} from <span class="hljs-string">'@/components/ui/card'</span>
import { Checkbox } from <span class="hljs-string">"@/components/ui/checkbox"</span>
import { Input } from <span class="hljs-string">'@/components/ui/input'</span>
import { Separator } from <span class="hljs-string">'@/components/ui/separator'</span>
import { createFileRoute } from <span class="hljs-string">'@tanstack/react-router'</span>

<span class="hljs-built_in">export</span> const Route = createFileRoute(<span class="hljs-string">'/dashboard/settings'</span>)({
  component: SettingsPage,
})

<span class="hljs-keyword">function</span> <span class="hljs-function"><span class="hljs-title">SettingsPage</span></span>() {
  <span class="hljs-built_in">return</span> (
    &lt;div className=<span class="hljs-string">"space-y-6"</span>&gt;
      &lt;div&gt;
        &lt;h3 className=<span class="hljs-string">"text-lg font-medium"</span>&gt;Settings&lt;/h3&gt;
        &lt;p className=<span class="hljs-string">"text-sm text-muted-foreground"</span>&gt;
          Manage your account settings and <span class="hljs-built_in">set</span> e-mail preferences.
        &lt;/p&gt;
      &lt;/div&gt;
      &lt;Separator /&gt;

      &lt;div className=<span class="hljs-string">"grid gap-6"</span>&gt;
        &lt;Card&gt;
          &lt;CardHeader&gt;
            &lt;CardTitle&gt;Profile&lt;/CardTitle&gt;
            &lt;CardDescription&gt;
              This is how others will see you on the site.
            &lt;/CardDescription&gt;
          &lt;/CardHeader&gt;
          &lt;CardContent className=<span class="hljs-string">"space-y-4"</span>&gt;
            &lt;div className=<span class="hljs-string">"flex items-center gap-4"</span>&gt;
              &lt;Avatar className=<span class="hljs-string">"h-20 w-20"</span>&gt;
                &lt;AvatarImage src=<span class="hljs-string">"https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-1.png"</span> /&gt;
                &lt;AvatarFallback&gt;JD&lt;/AvatarFallback&gt;
              &lt;/Avatar&gt;
              &lt;Button variant=<span class="hljs-string">"outline"</span>&gt;Change Avatar&lt;/Button&gt;
            &lt;/div&gt;
            &lt;div className=<span class="hljs-string">"space-y-1"</span>&gt;
              &lt;label htmlFor=<span class="hljs-string">"username"</span> className=<span class="hljs-string">"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"</span>&gt;Username&lt;/label&gt;
              &lt;Input id=<span class="hljs-string">"username"</span> defaultValue=<span class="hljs-string">"jdoe"</span> /&gt;
            &lt;/div&gt;
            &lt;div className=<span class="hljs-string">"space-y-1"</span>&gt;
              &lt;label htmlFor=<span class="hljs-string">"email"</span> className=<span class="hljs-string">"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"</span>&gt;Email&lt;/label&gt;
              &lt;Input id=<span class="hljs-string">"email"</span> defaultValue=<span class="hljs-string">"john.doe@example.com"</span> /&gt;
            &lt;/div&gt;
            &lt;div className=<span class="hljs-string">"space-y-1"</span>&gt;
              &lt;label htmlFor=<span class="hljs-string">"bio"</span> className=<span class="hljs-string">"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"</span>&gt;Bio&lt;/label&gt;
              &lt;Input id=<span class="hljs-string">"bio"</span> placeholder=<span class="hljs-string">"Tell us a little bit about yourself"</span> /&gt;
            &lt;/div&gt;
          &lt;/CardContent&gt;
          &lt;CardFooter&gt;
            &lt;Button&gt;Save Changes&lt;/Button&gt;
          &lt;/CardFooter&gt;
        &lt;/Card&gt;

        &lt;Card&gt;
          &lt;CardHeader&gt;
            &lt;CardTitle&gt;Notifications&lt;/CardTitle&gt;
            &lt;CardDescription&gt;
              Configure how you receive notifications.
            &lt;/CardDescription&gt;
          &lt;/CardHeader&gt;
          &lt;CardContent className=<span class="hljs-string">"space-y-4"</span>&gt;
            &lt;div className=<span class="hljs-string">"flex items-center justify-between rounded-lg border p-4"</span>&gt;
              &lt;div className=<span class="hljs-string">"space-y-0.5"</span>&gt;
                &lt;label className=<span class="hljs-string">"text-base font-medium"</span>&gt;Communication emails&lt;/label&gt;
                &lt;p className=<span class="hljs-string">"text-sm text-muted-foreground"</span>&gt;
                  Receive emails about your account activity.
                &lt;/p&gt;
              &lt;/div&gt;
              {/* Toggle would go here, using a simple checkbox <span class="hljs-keyword">for</span> now */}
              &lt;Checkbox defaultChecked /&gt;
            &lt;/div&gt;
            &lt;div className=<span class="hljs-string">"flex items-center justify-between rounded-lg border p-4"</span>&gt;
              &lt;div className=<span class="hljs-string">"space-y-0.5"</span>&gt;
                &lt;label className=<span class="hljs-string">"text-base font-medium"</span>&gt;Marketing emails&lt;/label&gt;
                &lt;p className=<span class="hljs-string">"text-sm text-muted-foreground"</span>&gt;
                  Receive emails about new products, features, and more.
                &lt;/p&gt;
              &lt;/div&gt;
              &lt;Checkbox /&gt;
            &lt;/div&gt;
          &lt;/CardContent&gt;
          &lt;CardFooter&gt;
            &lt;Button variant=<span class="hljs-string">"outline"</span>&gt;Update Preferences&lt;/Button&gt;
          &lt;/CardFooter&gt;
        &lt;/Card&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  )
}
</code></pre>
<p>In this page, we have created two sections:</p>
<ol>
<li><p>Profile Section</p>
</li>
<li><p>Notification Section</p>
</li>
</ol>
<p>These two sections have been built using shadcn/ui components like Card, Footer, Checkbox, Avatar, Input, and so on.</p>
<p>At this point, we have:</p>
<ul>
<li><p>A dashboard layout with sidebar, header, breadcrumbs, and footer</p>
</li>
<li><p>A Dashboard page with charts, insights, and a transaction table</p>
</li>
<li><p>A Products page powered by:</p>
<ul>
<li><p>TanStack Start server functions</p>
</li>
<li><p>TanStack Query</p>
</li>
<li><p>TanStack Table</p>
</li>
</ul>
</li>
<li><p>A clean Settings page using shadcn/ui components</p>
</li>
</ul>
<h2 id="heading-live-demo-amp-source-code">Live Demo &amp; Source Code</h2>
<p>You can check out the full source code on GitHub here:</p>
<ul>
<li><p>GitHub Repository: <a target="_blank" href="https://github.com/themeselection/tanstack-dashboard-demo">https://github.com/themeselection/tanstack-dashboard-demo</a></p>
</li>
<li><p>Live Demo: <a target="_blank" href="https://tanstack-dashboard-demo.vercel.app/dashboard">https://tanstack-dashboard-demo.vercel.app/dashboard</a></p>
</li>
</ul>
<p>Feel free to clone, experiment, and extend it to fit your own application needs!</p>
<h2 id="heading-summary">Summary</h2>
<p>Congratulations! You've built a complete, production-ready admin dashboard using TanStack Start, TanStack Table, TanStack Query, Shadcn/ui, and shadcn/studio.</p>
<p>Throughout this tutorial, you’ve gained some hands-on experience in:</p>
<ul>
<li><p><strong>Full-stack application development with type safety</strong>: We’ve developed a full-stack application with TanStack Start's server functions with Zod validation to create type-safe APIs.</p>
</li>
<li><p><strong>Advanced data fetching</strong>: We’ve implemented TanStack Query for data fetching with automatic caching and background updates.</p>
</li>
<li><p><strong>Complex table interactions</strong>: We’ve built feature-rich data tables with TanStack Table, including server-side pagination, sorting, and filtering.</p>
</li>
<li><p><strong>Building UI quicker</strong>: We’ve leveraged shadcn/ui and shadcn/studio blocks to quickly build polished interfaces.</p>
</li>
<li><p><strong>Responsive layouts</strong>: And we’ve created adaptive designs that work seamlessly from mobile to desktop</p>
</li>
</ul>
<h3 id="heading-whats-next">What’s Next?</h3>
<p>Now that you have a solid foundation, consider implementing some or all of the below features if you want to work more on this:</p>
<ul>
<li><p><strong>Authentication</strong>: Add user authentication with Clerk, NextAuth, or Auth.js</p>
</li>
<li><p><strong>Real database</strong>: Replace mock data with Prisma + PostgreSQL or Drizzle + SQLite</p>
</li>
<li><p><strong>Form validation</strong>: Integrate React Hook Form with Zod for robust form handling</p>
</li>
<li><p><strong>Theming</strong>: Implement dark mode and custom color schemes using shadcn/ui's theming system</p>
</li>
<li><p><strong>API routes for CRUD</strong>: Add CRUD operations for products (create, update, delete)</p>
</li>
<li><p><strong>Internationalization:</strong> Make the dashboard compatible with multiple languages by integrating internationalization.</p>
</li>
</ul>
<p>We shipped a scalable and production-ready dashboard much faster than starting from scratch. Hope you enjoyed the process – and thanks for reading!</p>
<h3 id="heading-resources">Resources:</h3>
<ul>
<li><p><a target="_blank" href="https://tanstack.com/start">TanStack Start Documentation</a></p>
</li>
<li><p><a target="_blank" href="https://tanstack.com/table">TanStack Table Docs</a></p>
</li>
<li><p><a target="_blank" href="https://tanstack.com/query">TanStack Query Docs</a></p>
</li>
<li><p><a target="_blank" href="https://shadcnstudio.com/components">Shadcn UI Components</a></p>
</li>
</ul>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
