| title | Frequently Asked Questions |
|---|
Here are some answers to frequently asked questions. If you have a question, you can ask it by opening an issue on the Storybook Repository.
Create React App does not allow providing options to Jest in your package.json, however you can run jest with commandline arguments:
npm test -- --coverage --collectCoverageFrom='["src/**/*.{js,jsx}","!src/**/stories/*"]'Next automatically defines React for all of your files via a babel plugin. In Storybook, you can solve this either by:
- Adding
import React from 'react'to your component files. - Adding a
.babelrcthat includesbabel-plugin-react-require
You can generally reuse webpack rules by placing them in a file that is require()-ed from both your next.config.js and your .storybook/main.js files. For example:
module.exports = {
webpackFinal: async (baseConfig) => {
const nextConfig = require('/path/to/next.config.js');
// merge whatever from nextConfig into the webpack config storybook will use
return { ...baseConfig };
},
};Fast refresh is an opt-in feature that can be used in Storybook React. There are two ways that you can enable it, go ahead and pick one:
- You can set a
FAST_REFRESHenvironment variable in your.envfile:
FAST_REFRESH=true
- Or you can set the following properties in your
.storybook/main.jsfiles:
module.exports = {
reactOptions: {
fastRefresh: true,
}
};A common error is that an addon tries to access the "channel", but the channel is not set. It can happen in a few different cases:
-
You're trying to access addon channel (e.g., by calling
setOptions) in a non-browser environment like Jest. You may need to add a channel mock:import addons, { mockChannel } from '@storybook/addons'; addons.setChannel(mockChannel());
-
In React Native, it's a special case documented in #1192
Not directly. If you control the component source, you can do something like this:
import React, { Component } from 'react';
export default {
title: 'MyComponent',
};
class MyComponent extends Component {
constructor(props) {
super(props);
this.state = {
someVar: 'defaultValue',
...props.initialState,
};
}
// ...
};
export const defaultView = () => <MyComponent initialState={} />;If you're adding Storybook's dependencies manually, make sure you include the @storybook/addon-controls dependency in your project and reference it in your .storybook/main.js as follows:
// .storybook/main.js
module.exports = {
addons: ['@storybook/addon-controls'],
};Composition is a new feature that we released with version 6.0, and there are still some limitations to it.
For now, the addons you're using in a composed Storybook will not work.
We're working on overcoming this limitation, and soon you'll be able to use them as if you are working with a non-composed Storybook.
Starting with Storybook version 6.0, we've introduced some great features aimed at streamlining your development workflow.
With this, we would like to point out that if you plan on using addons created by our fantastic community, you need to consider that some of those addons might be working with an outdated version of Storybook.
We're actively working in providing a better way to address this situation, but in the meantime, we would ask a bit of caution on your end so that you don't run into unexpected problems. Let us know by creating an issue in the Storybook repo so that we can gather information and create a curated list with those addons to help not only you but the rest of the community.
With the release of version 6.0, we updated our documentation as well. That doesn't mean that the old documentation was removed. We kept it to help you with your Storybook migration process. Use the content from the table below in conjunction with our migration guide .
We're only covering version 5.3 and 5.0 as they were important milestones for Storybook. If you want to go back in time a little more, you'll have to check the specific release in the monorepo.
storiesOf format has been removed. For the time being, we're still supporting it, and we have documentation for it. But be advised that this is bound to change in the future.
With the @storybook/components package, you get a set of icons that you can use to customize your own UI. Use the table below as a reference while writing your addon or defining your Storybook global types.
Go through this story to see how the icons look.
| accessibility | accessibilityalt | add | admin | alert |
|---|---|---|---|---|
| arrowdown | arrowleft | arrowleftalt | arrowright | arrowrightalt |
| arrowup | back | basket | batchaccept | batchdeny |
| beaker | bell | bitbucket | book | bookmark |
| bookmarkhollow | bottombar | box | branch | browser |
| button | calendar | camera | category | certificate |
| check | chevrondown | chromatic | circle | circlehollow |
| close | closeAlt | cog | collapse | comment |
| commit | compass | component | contrast | copy |
| cpu | credit | cross | dashboard | database |
| delete | discord | docchart | doclist | document |
| download | edit | ellipsis | expand | |
| expandalt | eye | eyeclose | facehappy | |
| faceneutral | facesad | filter | flag | folder |
| form | gdrive | github | gitlab | globe |
| graphbar | graphline | graphql | grid | |
| grow | heart | hearthollow | home | hourglass |
| info | key | lightning | lightningoff | link |
| listunordered | location | lock | markup | medium |
| memory | menu | merge | mirror | mobile |
| nut | outbox | outline | paintbrush | paperclip |
| paragraph | phone | photo | pin | play |
| plus | power | proceed | profile | |
| pullrequest | question | redirect | redux | reply |
| repository | requestchange | rss | search | share |
| sharealt | shield | sidebar | sidebaralt | speaker |
| star | starhollow | stop | structure | subtract |
| support | switchalt | sync | tablet | thumbsup |
| time | timer | transfer | trash | |
| undo | unfold | unlock | upload | user |
| useradd | useralt | users | video | watch |
| wrench | youtube | zoom | zoomout | zoomreset |
If you're using the serve package to verify your production build of Storybook, you'll get that error. It relates how serve handles rewrites. For instance, /iframe.html is rewritten into /iframe, and you'll get that error.
We recommend that you use http-server instead and use the following command to preview Storybook:
npx http-server storybook-statichttp-server as a development dependency and create a new script to preview your production build of Storybook.
Yes, with the release of version 6.2, Storybook now includes support for Vue 3. See the install page for instructions.
Yes, with the release of version 6.2, the Storyshots addon will automatically detect Vue 3 projects.
If you run into a situation where this is not the case, you can adjust the config object and manually specify the framework (e.g., vue3).
See our documentation on how to customize the Storyshots configuration.
Currently there's an issue when using MDX stories with IE11. This issue does not apply to DocsPage. If you're interested in helping us fix this issue, read our Contribution guidelines and submit a pull request.