Quick answer
shadcn/ui is not a component library you install. It is a collection of reusable components you copy into your own project, built on Radix UI primitives and styled with Tailwind CSS. You pick a Button, paste its code into src/components/ui, and it becomes your code to change. This post builds a shop orders list in a Vite and React app, adds a Button in the shadcn style, and fixes the build error that appears when the helper packages are missing.
A shop needs an orders page, and the page needs buttons: mark an order paid, cancel it, print it. The first version usually grows one button style per developer. A new button copies the classes of an old one, the copy drifts, and soon the page has four shades of the same button. A component library fixes the drift but adds a dependency you cannot change without a fork. shadcn/ui takes a third path: its components live in your project as plain files.
What I would check before using it
My first check is whether the project already uses Tailwind CSS. shadcn/ui components are Tailwind classes wrapped in React, so without Tailwind they render as unstyled text. If the project uses plain CSS or another styling system, adopting shadcn/ui means adopting Tailwind too, and that is a bigger decision than adding a button. The Tailwind CSS post covers how utility classes work.
My second check is whether the team wants to own its components. Copy-paste code means every fix and every upgrade is yours: when a new version of a component appears, you copy it again or merge it by hand. That ownership is the whole point for a small team that wants full control, and it is a burden for a team that would rather let a library handle updates.
My third check is accessibility. The components are built on Radix UI primitives, which handle keyboard navigation, focus, and ARIA attributes for dialogs, menus, and popovers. For a page of forms and buttons the gain is small, and the value is consistency instead.
My verdict, as judgement: adopt shadcn/ui when the project already runs Tailwind and the team wants components it can read and change. The recommendation flips if the project does not use Tailwind, or if the team needs versioned updates from a maintainer, because copy-paste code has no upgrade path.
Building a shop orders list with a copy-paste Button
The demo is an orders page for a shop in Karachi: three orders with customer, city, and total in PKR, a "Mark paid" button on each unpaid order, and an unpaid total at the top that updates on every click. Everything here is written by hand in the shadcn style.
The app is a Vite, React, and TypeScript scaffold with Tailwind CSS 4.3.5. Tailwind v4 needs no config file; the Vite plugin goes in vite.config.ts and one line in the stylesheet:
import tailwindcss from '@tailwindcss/vite' import react from '@vitejs/plugin-react' import { defineConfig } from 'vite' export default defineConfig({ plugins: [react(), tailwindcss()], }) @import "tailwindcss"; First, the cn helper in src/lib/utils.ts. It joins class names with clsx, then tailwind-merge resolves conflicts so a later class wins:
import { clsx, type ClassValue } from "clsx" import { twMerge } from "tailwind-merge" export function cn(...inputs: ClassValue[]) { return twMerge(clsx(inputs)) } Second, the Button in src/components/ui/button.tsx. Variants come from class-variance-authority, and the component is a plain button with classes merged through cn:
import { cva, type VariantProps } from "class-variance-authority" import * as React from "react" import { cn } from "../../lib/utils" const buttonVariants = cva( "inline-flex items-center justify-center gap-2 rounded-md text-sm font-medium transition-colors focus-visible:outline-2 focus-visible:outline-offset-2 disabled:pointer-events-none disabled:opacity-50", { variants: { variant: { default: "bg-slate-900 text-white hover:bg-slate-700", outline: "border border-slate-300 bg-white text-slate-900 hover:bg-slate-100", ghost: "text-slate-900 hover:bg-slate-100", }, size: { default: "h-9 px-4 py-2", sm: "h-8 px-3 text-xs", lg: "h-10 px-6", }, }, defaultVariants: { variant: "default", size: "default", }, }, ) export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> {} const Button = React.forwardRef<HTMLButtonElement, ButtonProps>( ({ className, variant, size, ...props }, ref) => { return ( <button className={cn(buttonVariants({ variant, size, className }))} ref={ref} {...props} /> ) }, ) Button.displayName = "Button" export { Button, buttonVariants } Third, the orders page in src/App.tsx. Three orders, a Mark paid button on the unpaid ones, and the unpaid total from state:
import { useState } from "react" import { Button } from "./components/ui/button" type Order = { id: string customer: string city: string total: number paid: boolean } const initialOrders: Order[] = [ { id: "ORD-1041", customer: "Ayesha Khan", city: "Karachi", total: 4850, paid: false }, { id: "ORD-1042", customer: "Bilal Ahmed", city: "Lahore", total: 12900, paid: false }, { id: "ORD-1043", customer: "Fatima Noor", city: "Islamabad", total: 7300, paid: true }, ] export default function App() { const [orders, setOrders] = useState<Order[]>(initialOrders) function markPaid(id: string) { setOrders((prev) => prev.map((order) => (order.id === id ? { ...order, paid: true } : order)), ) } const unpaidTotal = orders .filter((order) => !order.paid) .reduce((sum, order) => sum + order.total, 0) return ( <main className="mx-auto max-w-2xl p-6"> <h1 className="text-2xl font-bold">Shop orders</h1> <p className="mt-1 text-slate-600"> Unpaid total: PKR {unpaidTotal.toLocaleString("en-PK")} </p> <ul className="mt-6 space-y-3"> {orders.map((order) => ( <li key={order.id} className="flex items-center justify-between rounded-lg border border-slate-200 p-4" > <div> <p className="font-medium"> {order.id} - {order.customer} </p> <p className="text-sm text-slate-600"> {order.city} - PKR {order.total.toLocaleString("en-PK")} </p> </div> {order.paid ? ( <span className="rounded-full bg-green-100 px-3 py-1 text-xs font-medium text-green-800"> Paid </span> ) : ( <Button variant="outline" size="sm" onClick={() => markPaid(order.id)}> Mark paid </Button> )} </li> ))} </ul> </main> ) } Now the build, and it fails at once. The code imports clsx, tailwind-merge, and class-variance-authority, and none of them is installed yet:
$ npm run build > shop-ui@0.0.0 build > tsc -b && vite build src/components/ui/button.tsx(1,40): error TS2307: Cannot find module 'class-variance-authority' or its corresponding type declarations. src/lib/utils.ts(1,39): error TS2307: Cannot find module 'clsx' or its corresponding type declarations. src/lib/utils.ts(2,25): error TS2307: Cannot find module 'tailwind-merge' or its corresponding type declarations. Three missing modules, and the error names each one. The fix is one install, because these are ordinary runtime dependencies, not part of shadcn/ui itself:
$ npm install clsx tailwind-merge class-variance-authority $ npm run build > shop-ui@0.0.0 build > tsc -b && vite build vite v8.4.0 building client environment for production... transforming... ✓ 21 modules transformed. rendering chunks... computing gzip size... dist/index.html 0.45 kB │ gzip: 0.29 kB dist/assets/index-CNxzYogW.css 10.09 kB │ gzip: 2.88 kB dist/assets/index-DwsC8QSV.js 251.15 kB │ gzip: 78.67 kB ✓ built in 266ms The build passes, and the built bundle contains the order ids, the "Mark paid" text, and the unpaid total label. Clicking Mark paid on ORD-1041 flips that row to a Paid badge and drops the unpaid total from PKR 17,750 to PKR 12,900. The state update is a plain map over the orders array, and the React useEffect post explains when an effect would be needed instead.
Common mistakes and how to fix them
First, treating shadcn/ui as a package to install. The symptom is an import like import { Button } from "shadcn-ui" that resolves to nothing useful. The shadcn-ui package on npm is the CLI that copies components into your project, not a library of components, so there is no component import to write. The fix is to copy the component file into src/components/ui and import it from there.
Second, skipping the helper packages. The symptom is the build error above: TS2307, Cannot find module 'clsx', 'tailwind-merge', or 'class-variance-authority'. The fix is to install all three.
Third, mixing Tailwind versions. The symptom is a page that builds fine but renders with no styling at all. Tailwind v4 uses @import "tailwindcss" and the Vite plugin, while v3 used a tailwind.config.js file. The fix is to match the setup to the installed version: with v4, delete the old config file and keep the import line.
Fourth, pasting a component that needs a Radix package you have not installed. The symptom is another TS2307 error naming a package like @radix-ui/react-dialog. The fix is to install the named package.
Frequently Asked Questions
Is shadcn/ui a component library? No, and that is the point. A library ships compiled code you import; shadcn/ui ships source files you copy into your project and own. You can edit any line of it without waiting for a release.
Do I need Tailwind CSS to use shadcn/ui? Yes, in practice. The components are Tailwind classes, so without Tailwind they render unstyled. With another styling approach you would have to rewrite every class, which removes most of the benefit.
Can I use shadcn/ui without TypeScript? The official components are written in TypeScript, and the variants use types to stay safe. You can strip the types for plain JavaScript, but you lose the autocomplete on variant and size. The TypeScript post covers the type features used here.
Does shadcn/ui work with Next.js? Yes, and that is where most people meet it, because the docs show a Next.js setup first. The same copy-paste idea works in Vite, Remix, or any React app with Tailwind set up.
What to remember
- shadcn/ui is copy-paste source code you own, not a package you import components from.
- The Button needs three small packages: clsx, tailwind-merge, and class-variance-authority.
- cn merges class names and lets tailwind-merge settle conflicts between them.
- Tailwind v4 setup is the Vite plugin plus
@import "tailwindcss", with no config file. - Each interactive component may need its own Radix UI package installed separately.
Where this leaves you
The orders page now has one Button, used three times, with its style defined in one file instead of copied across the page. The build failed once on three missing packages, the fix was one install, and the rebuild passed. That is the whole shadcn/ui trade in miniature: a little setup, code you can read, and nothing hidden behind a version number. Copy one component into your own project this week and see how it feels to own it.
Further reading
- shadcn/ui documentation
- shadcn/ui Button component
- Tailwind CSS documentation
- React documentation
- Tailwind CSS Explained: Styling Without Leaving Your HTML
- React useEffect Explained: When to Use It and Skip It
- TypeScript Explained: Types That Catch Bugs Before They Run
- Storybook for React: Build Components Without the App
- Figma Explained: The Design Tool Developers Actually Receive
Waqas Shahid is a software engineer from Karachi with more than 12 years of experience, including 6+ years in engineering leadership. He writes The Practical Developer.
Originally published at https://practicaldevblog.blogspot.com/2026/11/shadcn-ui-shop-components-tutorial.html

