Make sure you align your storybook dependencies to the same major version or you will see broken behaviour.
Prerequisites
- Node.js 20 or higher
- An existing React Native or Expo project
- For Expo: Expo SDK 49 or higher
- For React Native CLI: React Native 0.72 or higher
Installation
Run the initialization command
Use the Storybook CLI to automatically set up Storybook in your project:The CLI will:
- Detect your project type (Expo or React Native CLI)
- Install required dependencies
- Create a
.rnstorybookconfiguration folder - Set up example stories
Update your Metro configuration
Wrap your Metro config with the
withStorybook function:- Expo
- React Native CLI
Create or update
metro.config.js:metro.config.js
Render Storybook in your app
Return Storybook’s UI in your app entry point:
- Direct Export
- Conditional Rendering
- Expo Router
The simplest approach - export Storybook directly:
App.tsx
Your first story
The CLI creates example stories for you. Let’s create a simple Button component story:Create a component
components/Button.tsx
Write a story
components/Button.stories.tsx
Configure story paths
Update.rnstorybook/main.ts to tell Storybook where to find your stories:
.rnstorybook/main.ts
Add interactivity with addons
Install on-device addons to add interactive controls:.rnstorybook/main.ts:
.rnstorybook/main.ts
Troubleshooting
Metro bundler errors
Metro bundler errors
If you see Metro errors about
require.context, make sure you’ve wrapped your Metro config with withStorybook() and restarted the Metro bundler.Reanimated errors
Reanimated errors
Ensure
react-native-reanimated/plugin is the last plugin in your babel.config.js and restart your app with cache cleared: npx expo start --clear or npm start -- --reset-cache.TypeScript errors
TypeScript errors
Add the Storybook types to your
tsconfig.json:tsconfig.json
Stories not appearing
Stories not appearing
Make sure your story file paths in
.rnstorybook/main.ts match your actual file locations. Run the generate command to regenerate the story index: npx sb-rn-get-stories.Next steps
Writing stories
Learn the Component Story Format syntax
Addons
Explore available on-device addons
Configuration
Configure Metro and Storybook options
Testing
Use stories in your unit tests