Fireship · @fireship
Storybook in 100 Seconds
Uploaded June 27, 2022 · Length 2:19
Summary
storybook tutorial: build, test, and visualize ui components in isolation with a guidebook and test runner.
- storybook
- ui components
- testing
- frontend development
- component frameworks
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:00
storybook an open source tool used to
- 0:02
build test and visualize ui components
- 0:05
in isolation modern web developers love
- 0:07
component frameworks because they
- 0:09
organize html css and javascript code
- 0:12
into reusable chunks like lego bricks
- 0:14
however a complex codebase can still
- 0:16
easily descend into chaos causing
- 0:18
components to lose their meaning in life
- 0:20
storybook allows developers to extract
- 0:22
components into a sandbox where they can
- 0:24
be explored and tested without
- 0:26
distractions instead of viewing
- 0:27
components through the lens of a giant
- 0:29
complex component tree that is your
- 0:31
application you get a guidebook that
- 0:33
breaks everything down individually no
- 0:35
need to worry about data dependencies or
- 0:37
business logic this makes it much easier
- 0:38
to share your work with other developers
- 0:40
or clients who can validate that things
- 0:42
actually work the way they're supposed
- 0:43
to in addition it has a test runner
- 0:45
based on jest and playwright that can
- 0:47
automatically verify whether your
- 0:49
component renders without errors and
- 0:50
also validate concerns like
- 0:52
accessibility measure performance and
- 0:54
can even do visual regression testing in
- 0:56
the cloud to pinpoint everything you
- 0:57
broke with that last css tweak to get
- 1:00
started create a project with your
- 1:01
favorite front-end framework like react
- 1:03
angular view spelt and so on or open an
- 1:05
existing one then run npx storybook init
- 1:07
next find a ui component then create a
- 1:09
matching file ending dot stories.js a
- 1:12
story is just a function that describes
- 1:14
how to render the component in many
- 1:16
cases a component will have multiple
- 1:18
different variations to show in the
- 1:20
story export a function for each one of
- 1:22
these variations that works but we can
- 1:24
actually change the arguments to a
- 1:26
component dynamically directly in the ui
- 1:28
by creating a template that maps
- 1:30
arguments to the component we can now
- 1:31
change the component's behavior on the
- 1:33
fly directly in the storybook ui it's
- 1:35
also possible to write stories in
- 1:37
markdown with mdx this allows you to not
- 1:40
only visualize the component but also
- 1:42
document it at the same time and there's
- 1:44
a huge collection of add-ons to
- 1:45
customize the behavior of your storybook
- 1:47
you might use actions to keep track of
- 1:49
browser events or viewport to analyze
- 1:51
components on responsive layouts and the
- 1:53
measure add-on can help you visually
- 1:55
debug css layout and alignment issues
- 1:57
within your stories when it comes to
- 1:59
testing you could spot check with your


