In CSF, stories and component metadata are defined as ES6 modules. Every Component story file consists of a required default export and one or more named exports.

CSF is supported in all frameworks except React Native, where you should use the storiesOf API instead.

The default export defines metadata about your component, including the itself, its title (where it will show up in the ), decorators, and . title should be unique, i.e. not re-used across files.

For more examples, see writing stories

Story functions can be annotated with a story object to define story-level and parameters, and also to define the name of the story.

The name is useful if you want to use names with spaces, names that correspond to restricted keywords in Javascript, or names that collide with other variables in the file. If it’s not specified, the export name will be used instead.

Storybook handles named exports and slightly differently. When should you use one vs. the other?

In general, you should use named exports. Storybook passes them through a storyNameFromExport function (), which is implemented with lodash.startCase:

You should use the story.name option in the following cases:

  • Want the name to show up in the Storybook UI in a way that’s not possible with a named export, e.g. reserved keywords like “default”, special characters like emoji, spacing/capitalization other than what’s provided by storyNameFromExport

In some cases, you may want to export a mixture of story and non-stories. For example., it can be useful to export data that’s used in your stories.

To make this possible, you can use optional includeStories and configuration fields in the default export, which can be set to either an array of strings, or a regular expression.

Consider the following story file:

For this specific example the equivalent result can be achieved in a few ways depending on what’s convenient:

  • includeStories: ['simpleStory', 'complexStory']
  • includeStories: /.*Story$/