Why Storybook?
Storybook lets you develop UI components in isolation — outside your app. Each component gets a "story" showing its states. Perfect for design systems.
npx storybook@latest init
npm run storybook
Write a Story
// Button.stories.tsx
import type { Meta, StoryObj } from '@storybook/react'
import { Button } from './Button'
const meta: Meta<typeof Button> = {
component: Button,
tags: ['autodocs'],
}
export default meta
type Story = StoryObj<typeof Button>
export const Primary: Story = {
args: { variant: 'primary', children: 'Click me' },
}
export const Secondary: Story = {
args: { variant: 'secondary', children: 'Cancel' },
}
export const Disabled: Story = {
args: { variant: 'primary', children: 'Submit', disabled: true },
}
export const Loading: Story = {
args: { variant: 'primary', children: 'Saving...', loading: true },
}
Interactive Tests
import { within, userEvent, expect } from '@storybook/test'
export const ClickTest: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement)
const button = canvas.getByRole('button')
await userEvent.click(button)
await expect(button).toHaveTextContent('Clicked!')
},
}
Auto-Generated Docs
Storybook reads your TypeScript props and generates documentation automatically — every prop, every type, every default value.
Visual Regression Testing
npm install @storybook/addon-storyshots
Capture screenshots of every story. On next run, compare pixel-by-pixel.
Need to extract data from any website at scale? I build custom web scrapers — 77 production scrapers running on Apify Store. Email me at spinov001@gmail.com for a tailored solution.
Top comments (0)