Skip to content
matthewcm.dev

    ↑ ↓ move · ↵ open · tab scopeopen graph →

    Storybook

    Components rendered in isolation, one story per state — living documentation, a test bench and a stakeholder demo in one. Most valuable when every requirement gets a story.

    Growingtended planted 1 min read
    On this page

    Storybook renders components outside your app, one story per meaningful state: empty, loading, error, a thousand rows, a very long name. That simple idea ends up doing several jobs at once.

    The jobs it does

    • Component-driven development. Build a component in isolation, against every state, before wiring it into a page. Edge cases become visible instead of theoretical.
    • Living documentation. Autodocs generate prop tables from TypeScript; stories show usage. Docs that are also running code don’t rot as fast.
    • A test bench. Interaction tests (play functions), accessibility checks and visual regression all run against the same stories.
    • A demo without a meeting. Stakeholders can click through progress themselves.

    The habit that makes it work

    One story per requirement. When every functional requirement has a story, Storybook becomes the shared definition of done: product can see it, developers can build features in parallel without stepping on each other, and tests have fixtures ready-made.

    Gotchas I’ve hit

    • Shared mutable args. Stories that mutate shared args or context leak state into each other. Treat args as immutable.
    • Iframes and viewport units. 100vh/100vw layouts behave oddly inside Storybook’s iframe.
    • Interaction tests share an environment with the rest of your test runner. Sometimes a plain integration test is simpler.
    • Package vs source. Stories next to components are fastest for development, but you also need to prove the built package imports and renders in a consuming app.

    In practice

    I’ve used Storybook for a corporate component library and, most heavily, for an in-house network graph library, where it was the docs, the demo and the test harness at once — the story is in Building a Graph Component Library. The design principles that make components story-friendly are in Headless Component Libraries, and stories as test fixtures fit neatly into React Testing Strategy.

    • #storybook
    • #component-libraries
    • #design-systems
    • #testing
    • #documentation

    ↪ Links to (3)