Storybook in React: Showcase Components with Ease

Aman GuptaAman Gupta
2 min read

Introduction
When building frontend apps, how many times have you launched your full app just to test a small component — like a Button?

What if you could test, tweak, and share UI components in isolation, without spinning up your entire app?

That’s exactly what Storybook enables.

Let’s understand it using a simple real-world analogy.

Think of your Web App as a Shopping Mall
Imagine your entire React app is like a giant shopping mall.

Inside, you have:

  • Modals (Changing Rooms),

  • Buttons (Mannequins),

  • Forms (Checkout Counters),

  • Navigation Bars (Security Staff), and so on.

Now, let’s say you’re designing a button. Do you really want to:
Boot up the full app,

Log in,

Navigate 3 pages deep...
just to see how one button looks?

👗 Enter Storybook — The Component Dressing Room
Storybook lets you move that single component (like your button) into a clean, isolated environment, where you can:

✅ See it in action
✅ Change its props
✅ Test multiple states (loading, disabled, active)
✅ Share it with your designers or product team — without touching your main app

Step-by-Step Example: Using Storybook in React + TypeScript with a Button Component

Step 1: Install Storybook
In your existing React + TypeScript project, run this:

npx storybook@latest init

This will:
Create a .storybook/ folder with config
Add example stories
Install necessary dependencies

Step 2: Create a Simple Button Component
Create a file:
src/components/Button.tsx

type Props = {
  label: string;
  disabled?: boolean;
};

export const Button = ({ label, disabled = false }: Props) => {
  return <button disabled={disabled}>{label}</button>;
};

🔹 This is a simple, reusable button component written in TypeScript.

Step 3: Create the Storybook Story for This Component
Create the story file:
src/components/Button.stories.tsx


import { Button } from './Button';

export default {
  title: 'Components/Button',
  component: Button,
};

export const Primary = () => <Button label="Click me" />;
export const Disabled = () => <Button label="Can’t click" disabled />;

Step 4: Run Storybook
In your terminal, run:

npm run storybook

Storybook will launch at :http://localhost:6006

You’ll now see:

  • A "Components" section

  • Your Button component under it

  • "Primary" and "Disabled" states rendered and clickable

What We’ve Done:

  • Set up Storybook

  • Created a TypeScript React component

  • Wrote clean stories with props

  • Ran Storybook to preview components

0
Subscribe to my newsletter

Read articles from Aman Gupta directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Aman Gupta
Aman Gupta

I am a passionate Frontend Developer who thrives on turning complex ideas into compelling, scalable, and user-centric digital experiences. Over time, I’ve successfully developed a diverse range of projects, including: My technical expertise spans JavaScript, TypeScript, React, Redux, Node.js, Express.js, Next.js, HTML, CSS, and Git, allowing me to craft efficient, responsive, and visually appealing applications. I am driven by continuous learning and adapt as technology evolves. Working within agile teams has honed my communication and collaboration skills, ensuring that I can translate requirements into robust solutions. Whether it’s building a production-ready web applications with robust AI integrations, delivering intelligent solutions that adapt to evolving market needs and end-user expectations, integrating secure payments, or optimizing code architecture and performance, I approach each project with a commitment to innovation, scalability, and user satisfaction. Let’s work together to create digital solutions that solve real-world challenges, delight end-users, and drive meaningful results!