Storybook Cheat Sheet
Component story format (CSF3), args, decorators, addons, and interaction testing syntax for building an isolated UI component workshop.
CSF3 Story File
Modern Component Story Format: default export is meta, named exports are stories.
// Button.stories.tsximport type { Meta, StoryObj } from '@storybook/react'import { Button } from './Button'const meta: Meta<typeof Button> = { title: 'Components/Button', component: Button, args: { children: 'Click me' }, argTypes: { variant: { control: 'select', options: ['primary', 'secondary', 'ghost'] }, },}export default metatype Story = StoryObj<typeof Button>export const Primary: Story = { args: { variant: 'primary' } }export const Disabled: Story = { args: { disabled: true } }
Decorators & Providers
Wrap every story in a component's file (or globally) with required context/providers.
const meta: Meta<typeof Cart> = { component: Cart, decorators: [ (Story) => ( <ThemeProvider theme="light"> <Story /> </ThemeProvider> ), ],}// .storybook/preview.tsx — applies globallyexport const decorators = [ (Story) => <QueryClientProvider client={queryClient}><Story /></QueryClientProvider>,]
Play Function (Interaction Testing)
Simulate user interactions and assert on results directly inside the story.
import { within, userEvent, expect } from '@storybook/test'export const SubmitsForm: Story = { play: async ({ canvasElement }) => { const canvas = within(canvasElement) await userEvent.type(canvas.getByLabelText('Email'), 'a@b.com') await userEvent.click(canvas.getByRole('button', { name: /submit/i })) await expect(canvas.getByText('Success')).toBeInTheDocument() },}
Mocking API Calls with msw
Use Mock Service Worker addon to intercept requests inside a story.
import { http, HttpResponse } from 'msw'export const LoadedState: Story = { parameters: { msw: { handlers: [ http.get('/api/user', () => HttpResponse.json({ name: 'Ana' })), ], }, },}
CLI & Config Essentials
Commands and files you touch on every project.
- npx storybook@latest init- bootstrap Storybook into an existing project, auto-detects framework
- npm run storybook- runs the dev server, default port 6006
- npm run build-storybook- builds a static Storybook site for deployment
- .storybook/main.ts- addons list, stories glob pattern, framework config
- .storybook/preview.ts- global parameters, decorators, and argTypes applied to all stories
- chromatic (addon)- visual regression testing/hosting service built for Storybook
Write stories for edge/error states (empty list, loading, error, very long text) as first-class exports, not just the happy path — those are exactly the states that are hardest to reproduce manually and where Storybook's isolation pays off most.
Explore Topics
Professional Web Designing Services
- Responsive Websites
- E-commerce Solutions
- SEO Friendly Design
- Fast & Secure
- Support & Maintenance