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 ButtonProps = {
label: string;
disabled?: boolean;
};
export const Button = ({ label, disabled = false }: ButtonProps) => {
return {label};
};
`
πΉ 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 = () => ;
export const 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
Top comments (0)