# Migration - [Migration](#migration) - [From version 10 to 11](#from-version-10-to-11) - [Update Storybook dependencies to 11.x](#update-storybook-dependencies-to-11x) - [On-device addons must be listed in `deviceAddons`](#on-device-addons-must-be-listed-in-deviceaddons) - [Move `storySort` to `storySorts` in main](#move-storysort-to-storysorts-in-main) - [Backgrounds are built in and enabled by default](#backgrounds-are-built-in-and-enabled-by-default) - [Controls are built in and enabled by default](#controls-are-built-in-and-enabled-by-default) - [From version 10.3 to 10.4](#from-version-103-to-104) - [Update your metro config](#update-your-metro-config) - [Simplify your App.tsx (or Expo Router routes)](#simplify-your-apptsx-or-expo-router-routes) - [Regenerate your requires file](#regenerate-your-requires-file) - [Move on-device addons to `deviceAddons`](#move-on-device-addons-to-deviceaddons) - [Summary of breaking changes](#summary-of-breaking-changes) - [Migrate to entry-point swapping](#migrate-to-entry-point-swapping) - [From version 9 to 10](#from-version-9-to-10) - [Update Storybook dependencies to 10.x](#update-storybook-dependencies-to-10x) - [From version 8 to 9](#from-version-8-to-9) - [Update Storybook dependencies to 9.x](#update-storybook-dependencies-to-9x) - [Update your `.storybook` folder](#update-your-storybook-folder) - [Regenerate your requires file](#regenerate-your-requires-file-1) - [From version 7.6.x to 8.3.x](#from-version-76x-to-83x) - [Dependencies](#dependencies) - [Regenerate your requires file](#regenerate-your-requires-file-2) - [Update your metro config](#update-your-metro-config-1) - [From version 6.5.x to 7.6.x](#from-version-65x-to-76x) - [Dependencies](#dependencies-1) - [Regenerate your requires file](#regenerate-your-requires-file-3) - [Update `.storybook/index.js`](#update-storybookindexjs) - [Metro config](#metro-config) - [Expo](#expo) - [React Native CLI](#react-native-cli) - [Types](#types) - [doctools](#doctools) - [(optional) react-native-server](#optional-react-native-server) - [First install necessary packages](#first-install-necessary-packages) - [Update package.json scripts](#update-packagejson-scripts) - [Create .storybook-web config folder](#create-storybook-web-config-folder) - [6.5.x to 7.6.x with storiesOf support](#65x-to-76x-with-storiesof-support) - [Update dependencies](#update-dependencies) - [Update your package.json scripts](#update-your-packagejson-scripts) - [Regenerate your requires file](#regenerate-your-requires-file-4) - [Update `.storybook/index.js`](#update-storybookindexjs-1) - [Update your stories](#update-your-stories) - [Types](#types-1) - [From version 5.3.x to 6.5.x](#from-version-53x-to-65x) - [Additional dependencies](#additional-dependencies) - [Controls (the new knobs)](#controls-the-new-knobs) - [Actions](#actions) - [`.storybook` folder](#storybook-folder) - [Update your `index.js` file](#update-your-indexjs-file) - [Add a `main.js` and `preview.js`](#add-a-mainjs-and-previewjs) - [Scripts in package.json](#scripts-in-packagejson) - [Update your metro config](#update-your-metro-config-2) - [Convert your stories to CSF](#convert-your-stories-to-csf) - [Theming](#theming) - [Test ids for tabs](#test-ids-for-tabs) - [The server](#the-server) ## From version 10 to 11 ### Update Storybook dependencies to 11.x You need to update all Storybook dependencies to version 11.x. This includes: - `storybook` package (core) - `@storybook/react` package - `@storybook/react-native` package - `@storybook/addon-ondevice-notes`, if you use it You don't need to update `@storybook/addon-ondevice-actions`, `@storybook/addon-ondevice-backgrounds` or `@storybook/addon-ondevice-controls`: Actions, Backgrounds and Controls are now built into `@storybook/react-native`, so you can uninstall those three (see [Actions](#actions-is-built-into-storybookreact-native), [Backgrounds](#backgrounds-are-built-in-and-enabled-by-default) and [Controls](#controls-are-built-in-and-enabled-by-default) below). > Note: You can check the correct version by looking at the `peerDependencies`. Please refer to the [core Storybook migration guide](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md) for more details on the breaking changes in Storybook core v11. **Example package.json after upgrade:** ```json { "devDependencies": { "@storybook/react-native": "^11.0.0", "@storybook/react": "^11.0.0", "@storybook/addon-ondevice-notes": "^11.0.0", "storybook": "^11.0.0" } } ``` ### On-device addons must be listed in `deviceAddons` `.rnstorybook/main.ts` no longer reads `addons`. Entries left there are ignored and are not written into `storybook.requires`. Move every entry into `deviceAddons`. That includes `@storybook/addon-ondevice-notes`, other addons you bundle with the app, and local paths. Actions, Backgrounds and Controls are now built in, so don't move `@storybook/addon-ondevice-actions`, `@storybook/addon-ondevice-backgrounds` or `@storybook/addon-ondevice-controls`; remove them instead (see the sections below). A web Storybook config, such as `@storybook/react-native-web-vite` in `.storybook/main.ts`, keeps its own `addons` field. `definePreview({ addons })` is also unchanged: that array is preview annotations, not the main-config list. ```ts // Before (.rnstorybook/main.ts) const main: StorybookConfig = { stories: ['../components/**/*.stories.?(ts|tsx|js|jsx)'], addons: ['@storybook/addon-ondevice-notes', './local-addon/register'], }; // After const main: StorybookConfig = { stories: ['../components/**/*.stories.?(ts|tsx|js|jsx)'], deviceAddons: ['@storybook/addon-ondevice-notes', './local-addon/register'], }; ``` If `deviceAddons` is not set yet, the Storybook CLI automigration `rn-ondevice-addons-to-device-addons` renames the field for you: ```sh npx storybook automigrate ``` When both fields are already set, that automigration leaves the file alone so it does not overwrite `deviceAddons`. Move the remaining `addons` entries yourself. ### Move `storySort` to `storySorts` in main Storybook 11 no longer reads `parameters.options.storySort` from preview. Configure story sorting with the `storySorts` array in main instead. Each sorter only orders the stories that the sorters before it consider equal. See the [core Storybook migration guide](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#storysort-in-the-preview-replaced-by-storysorts-in-main). Storybook's automigration moves statically readable object and array configurations for you: ```sh npx storybook automigrate story-sort-to-main --config-dir .rnstorybook ``` Before: ```ts // .rnstorybook/preview.tsx export default definePreview({ addons: [], parameters: { options: { storySort: { order: ['Introduction', 'Components'] }, }, }, }); ``` After: ```ts // .rnstorybook/main.ts export default defineMain({ stories: ['../components/**/*.stories.?(ts|tsx|js|jsx)'], storySorts: [{ order: ['Introduction', 'Components'] }], }); ``` Comparator functions need to be moved by hand. They work in `storySorts`, but they are copied into `storybook.requires` from their source, so they can't use imports or variables from outside their own body. ### Actions is built into `@storybook/react-native` The on-device Actions panel now ships with `@storybook/react-native` and is enabled by default. `@storybook/addon-ondevice-actions` is deprecated and is now an empty stub: its `register` adds nothing, so the panel you see comes from `@storybook/react-native`. Remove the package from `deviceAddons` and uninstall it: ```ts // Before (.rnstorybook/main.ts) const main: StorybookConfig = { stories: ['../components/**/*.stories.?(ts|tsx|js|jsx)'], deviceAddons: ['@storybook/addon-ondevice-notes', '@storybook/addon-ondevice-actions'], }; // After const main: StorybookConfig = { stories: ['../components/**/*.stories.?(ts|tsx|js|jsx)'], deviceAddons: ['@storybook/addon-ondevice-notes'], }; ``` ```sh npm uninstall @storybook/addon-ondevice-actions ``` If you leave it listed, nothing breaks: you still get a single Actions panel, and a warning is logged once in development. Your stories don't need to change. To turn the Actions panel off, set `features: { ondeviceActions: false }` in `.rnstorybook/main.ts`. ### Backgrounds are built in and enabled by default The Backgrounds panel that shipped behind `features.ondeviceBackgrounds` in 10.3 is now on by default. You don't need `@storybook/addon-ondevice-backgrounds` anymore. Stories without `parameters.backgrounds` don't change: no background is applied until you configure options. To turn the built-in panel off, set the flag to `false`: ```ts // .rnstorybook/main.ts const main: StorybookConfig = { stories: ['../components/**/*.stories.?(ts|tsx|js|jsx)'], features: { ondeviceBackgrounds: false, }, }; ``` If you had `ondeviceBackgrounds: true`, you can remove it. `@storybook/addon-ondevice-backgrounds` is deprecated and kept as a compatibility stub, so existing projects don't break. Its `register` entry registers nothing and logs a warning in development, and `withBackgrounds` renders the story unchanged so backgrounds aren't applied twice. The built-in panel still reads the legacy `values` array and `default` name: values are keyed by `name`, and `default` (or the first value) is applied while no `backgrounds` global is set. To finish migrating: 1. Remove `'@storybook/addon-ondevice-backgrounds'` from `deviceAddons`. 2. Remove `withBackgrounds` from your preview `decorators`. 3. Uninstall the package. 4. Optionally move from `values`/`default` to `options` and `initialGlobals`: ```diff // .rnstorybook/preview.tsx -import { withBackgrounds } from '@storybook/addon-ondevice-backgrounds'; const preview: Preview = { - decorators: [withBackgrounds], parameters: { backgrounds: { - default: 'plain', - values: [ - { name: 'plain', value: 'white' }, - { name: 'dark', value: '#333' }, - ], + options: { + plain: { name: 'Plain', value: 'white' }, + dark: { name: 'Dark', value: '#333' }, + }, }, }, + initialGlobals: { + backgrounds: { value: 'plain' }, + }, }; ``` A story-level `default` becomes `globals: { backgrounds: { value: 'dark' } }` on that story. Stories with `parameters.backgrounds.disable: true` now also get no background, matching Storybook web. See the [Backgrounds guide](https://storybookjs.github.io/react-native/docs/intro/configuration/backgrounds). ### Controls are built in and enabled by default The Controls panel is now part of `@storybook/react-native` and is **on by default**. You no longer need `@storybook/addon-ondevice-controls`. 1. Remove `@storybook/addon-ondevice-controls` from `deviceAddons` in `.rnstorybook/main.ts` and uninstall it. 2. Restart your bundler so `storybook.requires.ts` is regenerated. ```diff const main: StorybookConfig = { deviceAddons: [ - '@storybook/addon-ondevice-controls', '@storybook/addon-ondevice-notes', ], }; ``` If you leave it in place, nothing breaks: `@storybook/addon-ondevice-controls` v11 is an empty stub whose `register` does nothing, so you still get exactly one Controls panel, plus a warning in development asking you to remove it. `@react-native-community/datetimepicker` and `@react-native-community/slider` are now **optional**: - Install and link them (rebuild the app) if you want the native date/time pickers and the native slider. - Without them, or in Expo Go, on tvOS/macOS or before a rebuild, the `date` control uses a JavaScript wheel picker (month, day and year, or hours and minutes) in the same bottom sheet and range controls use a JavaScript slider. A package that's installed but not linked falls back too, with a warning in development. - `react-native-modal-datetime-picker` is no longer used; uninstall it if nothing else needs it. To turn the built-in panel off, set the feature flag to `false`: ```ts const main: StorybookConfig = { features: { ondeviceControls: false, }, }; ``` If you imported `getControlArgTypes` or `hasEnabledControl` from `@storybook/addon-ondevice-controls/dist/controlArgTypes`, import them from `@storybook/react-native/controls`. The old path is removed. ## From version 10.3 to 10.4 ### Update your metro config The `withStorybook` metro wrapper has been significantly simplified in v10. The key changes are: 1. **BREAKING: Named import required** - `withStorybook` is now a named export instead of a default export 2. **Import path unified** - In v9, `withStorybookConfig` (from `metro/withStorybookConfig`) was a preview of the simplified API. In v10, this is now the standard behavior when importing `withStorybook` from `metro/withStorybook` 3. **`onDisabledRemoveStorybook` is removed** - When `enabled: false`, Storybook is automatically removed from the bundle (no separate flag needed) 4. **Simpler defaults** - Works out of the box with sensible defaults **Before (v9):** If you were using the preview `withStorybookConfig` (recommended approach in v9): ```js const { withStorybookConfig } = require('@storybook/react-native/metro/withStorybookConfig'); module.exports = withStorybookConfig(defaultConfig); ``` Or if you were using `withStorybook` with the old API (default export): ```js const withStorybook = require('@storybook/react-native/metro/withStorybook'); // ❌ Default export module.exports = withStorybook(defaultConfig, { enabled: process.env.STORYBOOK_ENABLED === 'true', onDisabledRemoveStorybook: true, // This option no longer exists in v10 configPath: path.resolve(__dirname, './.rnstorybook'), }); ``` **After (v10):** ```js const { withStorybook } = require('@storybook/react-native/metro/withStorybook'); // ✅ Named export // Basic usage - works out of the box with defaults module.exports = withStorybook(defaultConfig); // Or with options module.exports = withStorybook(defaultConfig, { // When false, automatically removes Storybook from bundle enabled: process.env.EXPO_PUBLIC_STORYBOOK_ENABLED === 'true', configPath: path.resolve(__dirname, './.rnstorybook'), }); ``` **Key improvements:** - **BREAKING:** Must use named import: `const { withStorybook } = require(...)` instead of default import - `withStorybookConfig` functionality is now the default behavior of `withStorybook` - When `enabled: false`, Storybook packages are automatically stubbed out (no need for `onDisabledRemoveStorybook`) - Default `configPath` is `./.rnstorybook` ### Simplify your App.tsx (or Expo Router routes) In v10, you can now directly import and export Storybook without worrying about bundle size or conditional imports. The metro config automatically handles everything. **Before (v9):** You couldn't safely import Storybook at the top level because it would be included in your production bundle, even when disabled. Then even if you used the onDisabledRemoveStorybook option you would still need to conditionally import Storybook in your app code to not cause a crash. ```tsx // App.tsx let AppEntryPoint = App; if (process.env.EXPO_PUBLIC_STORYBOOK_ENABLED === 'true') { // Conditional import to avoid bundling Storybook in production AppEntryPoint = require('./.rnstorybook').default; } export default AppEntryPoint; ``` **After (v10):** Now you can safely import Storybook at the top level - metro will automatically remove it when `enabled: false`: ```tsx // App.tsx import StorybookUI from './.rnstorybook'; // ✅ Safe! Metro stubs this out when enabled: false import { Text, View } from 'react-native'; const isStorybook = process.env.EXPO_PUBLIC_STORYBOOK_ENABLED === 'true'; // this could be your app entrypoint const AppComponent = () => { return ( Hello World ); }; export default function App() { return isStorybook ? : ; } ``` The key difference: the top-level `import` is now safe! Metro automatically stubs out the `.rnstorybook` import when `enabled: false`, removing all Storybook code from your production bundle. Or even simpler, with Expo Router, you can create a dedicated route and now not worry about conditional inline requires. ```tsx // app/storybook.tsx export { default } from '../.rnstorybook'; ``` **How it works:** The metro config (`enabled` flag) automatically handles bundle inclusion: - When `enabled: true` - Storybook is included in the bundle - When `enabled: false` - The `.rnstorybook` import is automatically stubbed out as an empty module, and all Storybook dependencies are removed **Key benefits:** - ✅ Import Storybook anywhere without bundle size concerns - ✅ Works seamlessly with Expo Router - just create a `/storybook` route - ✅ No more worrying about top-level imports bloating your production bundle - ✅ Metro handles all the complexity automatically ### Regenerate your requires file After updating dependencies and configuration, regenerate your `.rnstorybook/storybook.requires.ts` file: ```sh yarn storybook-generate ``` Or if you have the generate call in your metro config (recommended), just restart metro: ```sh yarn start --reset-cache ``` ### Move on-device addons to `deviceAddons` On-device addons should now be listed in the `deviceAddons` property instead of `addons` in your `.rnstorybook/main.ts`. This prevents errors during server-side operations like `extract`, where Storybook Core would try to evaluate React Native code as Node.js presets. **Before:** ```ts const main: StorybookConfig = { stories: ['../components/**/*.stories.?(ts|tsx|js|jsx)'], addons: ['@storybook/addon-ondevice-controls', '@storybook/addon-ondevice-actions'], }; ``` **After:** ```ts const main: StorybookConfig = { stories: ['../components/**/*.stories.?(ts|tsx|js|jsx)'], deviceAddons: ['@storybook/addon-ondevice-controls', '@storybook/addon-ondevice-actions'], }; ``` In 10.4, entries left in `addons` were still loaded. Version 11 [stops reading that field](#on-device-addons-must-be-listed-in-deviceaddons). The Storybook CLI automigration `rn-ondevice-addons-to-device-addons` renames the whole `addons` key to `deviceAddons` when `deviceAddons` is not already set. ### Summary of breaking changes 1. **Metro config API changes:** - **BREAKING:** `withStorybook` is now a named export - use `const { withStorybook } = require(...)` instead of default import - `withStorybookConfig` from `metro/withStorybookConfig` is removed - Use `withStorybook` from `metro/withStorybook` instead (the simplified API is now standard) - `onDisabledRemoveStorybook` option removed (automatic when `enabled: false`) 2. **Default config folder:** - Confirmed as `./.rnstorybook` (to avoid conflicts with web Storybook) 3. **Storybook core updated to v10:** - See [Storybook v10 migration guide](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#from-version-9x-to-1000) for core breaking changes 4. **Simplified app entry:** - Custom switcher components no longer needed for bundle optimization - In-app integration (importing Storybook in App.tsx) continues to work and is fully supported 5. **`deviceAddons` property:** - On-device addons should use the new `deviceAddons` property in `main.ts` - In 10.4, `addons` was still loaded. Version 11 no longer reads it. Version 10.4 introduces entry-point swapping through a bundler-agnostic `withStorybook` wrapper. This lets you switch between your app and Storybook at the bundler entry level, without importing Storybook inside `App.tsx`. ### Migrate to entry-point swapping Instead of importing Storybook in your `App.tsx`, set `STORYBOOK_ENABLED=true` and use the new wrapper: ```js // metro.config.js — new recommended import const { withStorybook } = require('@storybook/react-native/withStorybook'); module.exports = withStorybook(config); ``` Then run with `STORYBOOK_ENABLED=true expo start`. No changes to `App.tsx` are required. This is the recommended approach for new projects. Existing projects can migrate at their own pace — see [Migrating to Entry-Point Swapping](https://storybookjs.github.io/react-native/docs/intro/getting-started/migrating-to-entry-point-swapping) for a step-by-step guide. Version 10 brings Storybook React Native in sync with Storybook core v10, introducing improved Metro configuration and a simplified API. ## From version 9 to 10 ### Update Storybook dependencies to 10.x You need to update all Storybook dependencies to version 10.x. This includes: - `storybook` package (core) - `@storybook/react` package - `@storybook/react-native` package - All `@storybook/addon-ondevice-*` packages > Note: You can check the correct version by looking at the `peerDependencies`. Please refer to the [core Storybook migration guide](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#from-version-9x-to-1000) for more details on the breaking changes in Storybook core v10. **Example package.json after upgrade:** ```json { "devDependencies": { "@storybook/react-native": "^10.0.0", "@storybook/react": "^10.0.0", "@storybook/addon-ondevice-controls": "^10.0.0", "@storybook/addon-ondevice-actions": "^10.0.0", "@storybook/addon-ondevice-backgrounds": "^10.0.0", "@storybook/addon-ondevice-notes": "^10.0.0", "storybook": "^10.0.0" } } ``` ## From version 8 to 9 ### Update Storybook dependencies to 9.x You need to update all Storybook dependencies to version 9.x. This includes: - `storybook` package > Note: You can check the correct version by looking at the `peerDependencies`. Please refer to the [core Storybook migration guide](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md?#from-version-8x-to-900) for more details on the breaking changes of this package. - `@storybook/addon-ondevice-*` packages ### Update your `.storybook` folder For better compatibility with projects that includes both Storybook and Storybook React Native, the default configuration folder for Storybook React Native has been renamed from `.storybook/` to `.rnstorybook/`. ### Regenerate your requires file Regenerate your `.rnstorybook/storybook.requires.ts` file by running `yarn storybook-generate`. ## From version 7.6.x to 8.3.x In this version of storybook we've reworked the UI using some community react native packages. We've also overhauled the theme to match the web version. ### Dependencies Update all storybook dependencies to 8.3.5 or newer. For example you may end up with something like this ```json // package.json { "devDependencies": { "@storybook/react-native": "^8.3.5", "@storybook/react": "^8.3.5", "@storybook/addon-ondevice-controls": "^8.3.5", "@storybook/addon-ondevice-actions": "^8.3.5", "@storybook/addon-ondevice-backgrounds": "^8.3.5", "@storybook/addon-ondevice-notes": "^8.3.5" } } ``` Add the new required dependencies to your project. Expo: ```sh npx expo install react-native-reanimated react-native-gesture-handler @gorhom/bottom-sheet react-native-svg ``` RN Cli: ```sh npm install react-native-reanimated react-native-gesture-handler @gorhom/bottom-sheet react-native-svg ``` Make sure you use versions of those packages supported by your version of expo/react-native ### Regenerate your requires file Regenerate your `.storybook/storybook.requires.ts` file by running `yarn storybook-generate`. You should see a new `updateView` function in the file. ### Update your metro config ```js // metro.config.js const path = require('path'); const withStorybook = require('@storybook/react-native/metro/withStorybook'); module.exports = withStorybook(config, { // set to false to disable storybook specific settings // you can use a env variable to toggle this enabled: true, // path to your storybook config folder configPath: path.resolve(__dirname, './.storybook'), }); ``` For a full list of options, see [the `withStorybook` documentation](./README.md#withstorybook-wrapper). ## From version 6.5.x to 7.6.x In this version of storybook we've a lot of changes to the internals of react native storybook to make it more compatible with core storybook libraries. This means compatibility with the new v7 store and the api changes that comes with that. Here are some of the other improvements: - New storage option that lets you choose what storage solution you want to use (async storage/mmkv etc). - Support for main.ts - Dynamic imports enabled by the unstable_allowRequireContext option in metro config. - you only need to generate your requires file when main.ts changes. - Error boundaries for stories so your app shouldn't crash when a story throws an error. - Improved markdown renderer for notes addon. - Simpler setup for auto args. > [!NOTE] > You should follow a different set of changes if you need to support storiesOf, see [6.5.x to 7.6.x with storiesOf support](#65x-to-76x-with-storiesof-support) ### Dependencies Update all storybook dependencies to 7.6.10 or newer. For example you may end up with something like this ```json { "@storybook/react-native": "^7.6.10", "@storybook/addon-ondevice-actions": "^7.6.10", "@storybook/addon-ondevice-backgrounds": "^7.6.10", "@storybook/addon-ondevice-controls": "^7.6.10", "@storybook/addon-ondevice-notes": "^7.6.10" } ``` ### Regenerate your requires file Regenerate your `storybook.requires` file by running `yarn storybook-generate`. It should now generate a `storybook.requires.ts` file instead of a `storybook.requires.js` file. This provides the type for the new view export. ### Update `.storybook/index.js` Update `.storybook/index.js` to use the new `getStorybookUI` function on the `view` exported from `storybook.requires.ts`. You can also change this file to be called `.storybook/index.tsx`. You should also now pass a storage object to the `getStorybookUI` function. This is used to persist the selected story between reloads. ```tsx // .storybook/index.tsx import { view } from './storybook.requires'; import AsyncStorage from '@react-native-async-storage/async-storage'; const StorybookUIRoot = view.getStorybookUI({ storage: { getItem: AsyncStorage.getItem, setItem: AsyncStorage.setItem, }, }); export default StorybookUIRoot; ``` ### Metro config Update your `metro.config.js` to enable the `unstable_allowRequireContext` option and you can now remove the sbmodern resolver if you have it. > [!NOTE] > The unstable_allowRequireContext option requires at least react native 0.72 If you are using expo and you don't have a metro config file you can create one by running `npx expo customize metro.config.js`. You can also add here the generate function to automatically update the `storybook.requires.ts` file when you start metro. You only need to regenerate this file now when main.js updates since requireContext allows us to use dynamic imports. #### Expo ```js // metro.config.js const path = require('path'); const { getDefaultConfig } = require('expo/metro-config'); const { generate } = require('@storybook/react-native/scripts/generate'); generate({ configPath: path.resolve(__dirname, './.storybook'), }); /** @type {import('expo/metro-config').MetroConfig} */ const config = getDefaultConfig(__dirname); config.transformer.unstable_allowRequireContext = true; config.resolver.sourceExts.push('mjs'); module.exports = config; ``` #### React Native CLI ```js const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config'); const path = require('path'); const { generate } = require('@storybook/react-native/scripts/generate'); generate({ // update ./.storybook to your storybook folder configPath: path.resolve(__dirname, './.storybook'), }); const defaultConfig = getDefaultConfig(__dirname); /** * Metro configuration * https://facebook.github.io/metro/docs/configuration * * @type {import('metro-config').MetroConfig} */ const config = { transformer: { unstable_allowRequireContext: true, }, resolver: { sourceExts: [...defaultConfig.resolver.sourceExts, 'mjs'], }, }; module.exports = mergeConfig(defaultConfig, config); ``` You can now also remove anything from package.json scripts which would run generate before running storybook. ### Types We've removed the types from `@storybook/react-native` and now you should import them from `@storybook/react`. This is to remove duplication and increase compatibility with core storybook libraries. Heres an example story in version 7: ```ts import type { Meta, StoryObj } from '@storybook/react'; import { Button } from './Button'; const meta = { component: Button, argTypes: { onPress: { action: 'pressed the button' }, }, } satisfies Meta; export default meta; type Story = StoryObj; export const Basic: Story = { args: { text: 'Press me!', }, }; ``` You can now also update main.js to main.ts and use the StorybookConfig type. This is one of the only types we export from @storybook/react-native in this version. ```ts // .storybook/main.ts import type { StorybookConfig } from '@storybook/react-native'; const main: StorybookConfig = { stories: ['../components/**/*.stories.?(ts|tsx|js|jsx)'], deviceAddons: [ '@storybook/addon-ondevice-notes', '@storybook/addon-ondevice-controls', '@storybook/addon-ondevice-backgrounds', '@storybook/addon-ondevice-actions', ], }; export default main; ``` To update preview.js to preview.tsx you can use the Preview type from @storybook/react ```ts import type { Preview } from '@storybook/react'; const preview: Preview = { decorators: [] parameters: {} }; export default preview; ``` ### doctools If you are manually adding doctools to do auto args you can now remove this code since its automatically added now. To make it work you still need babel-plugin-react-docgen-typescript though. ```diff -import { extractArgTypes } from "@storybook/react/dist/modern/client/docs/extractArgTypes"; -import { addArgTypesEnhancer, addParameters } from "@storybook/react-native"; -import { enhanceArgTypes } from "@storybook/core/docs-tools"; -addArgTypesEnhancer(enhanceArgTypes); -addParameters({ - docs: { - extractArgTypes, - }, -}); ``` ### (optional) react-native-server In version 7 it wasn’t possible to update `@storybook/react-native-server` as it was. Instead we’ve released a new ReactJS addon called `@storybook/addon-react-native-server`. With this new addon you will need to setup a ReactJS storybook with a separate storybook config. The benefit of this setup is that its possible to get a web preview of the components if your components are compatible with react-native-web. There will shortly be a proper guide to setting this up, however the basics will be covered here. The setup is the same as `@storybook/addon-react-native-web` but with the reactNativeServerOptions property in the config file. #### First install necessary packages ```sh yarn add -D @storybook/addon-react-native-web @storybook/addon-essentials storybook @storybook/react-webpack5 @storybook/react babel-plugin-react-native-web react-native-web @storybook/addon-react-native-server ``` With expo you should also add `@expo/metro-runtime`. #### Update package.json scripts ```json "storybook:web": "storybook dev -p 6006 -c .storybook-web", "build-storybook": "storybook build -c .storybook-web" ``` #### Create .storybook-web config folder Add a `main.ts` ```ts // .storybook-web/main.ts import type { StorybookConfig } from '@storybook/react-webpack5'; type ServerStorybookConfig = StorybookConfig & { reactNativeServerOptions: { host: string; port: number }; }; const main: ServerStorybookConfig = { stories: ['../components/**/*.stories.?(ts|tsx|js|jsx)'], addons: [ '@storybook/addon-essentials', '@storybook/addon-react-native-web', '@storybook/addon-react-native-server', ], framework: { name: '@storybook/react-webpack5', options: {}, }, reactNativeServerOptions: { // for android you should use your local ip address here host: 'localhost', port: 7007, }, docs: { autodocs: 'tag', }, }; export default main; ``` Add a `preview.tsx` ```tsx // .storybook-web/preview.tsx import type { Preview } from '@storybook/react'; const preview: Preview = { decorators: [], parameters: { actions: { argTypesRegex: '^on[A-Z].*' }, controls: { matchers: { color: /(background|color)$/i, date: /Date$/, }, }, }, }; export default preview; ``` In your `.storybook/index.tsx` file where you call `view.getStorybookUI` make sure you enable Web sockets and match the host and port config from your `.storybook-web/main.ts`. ```tsx import { view } from './storybook.requires'; import AsyncStorage from '@react-native-async-storage/async-storage'; const StorybookUIRoot = view.getStorybookUI({ storage: { getItem: AsyncStorage.getItem, setItem: AsyncStorage.setItem, }, enableWebsockets: true, host: 'localhost', port: 7007, }); export default StorybookUIRoot; ``` Now just make sure you run `storybook:web` before running your React Native Storybook and you should be able to sync up your stories between web and your mobile devices. ## 6.5.x to 7.6.x with storiesOf support Storybook v7 doesn't support storiesOf in the same way as v6, but there is a compatibility mode that allows you to continue using storiesOf whilst you migrate your stories. > [!WARNING] > By opting into this compatibility mode you will lose out on some features of v7. We highly recommend moving to CSF stories. > > StoriesOf will be removed in v8 along with knobs and testing on those deprecated features will be limited. ### Update dependencies Update all storybook dependencies to 7.6.10 or newer. For example you may end up with something like this ```json { "@storybook/react-native": "^7.6.10", "@storybook/addon-ondevice-actions": "^7.6.10", "@storybook/addon-ondevice-backgrounds": "^7.6.10", "@storybook/addon-ondevice-controls": "^7.6.10", "@storybook/addon-ondevice-notes": "^7.6.10" } ``` ### Update your package.json scripts To opt in you can pass --v6-store to sb-rn-get-stories in the generate script. ```json { "scripts": { "storybook-generate": "sb-rn-get-stories --v6-store" } } ``` You should also now import storiesOf from `@storybook/react-native/V6` this is necessary so that certain code paths don't run in v7 mode. ### Regenerate your requires file Now that you've updated the script you can regenerate your `storybook.requires.js` file by running `yarn storybook-generate`. It should now have the updated `@storybook/react-native/V6` import in it. ### Update `.storybook/index.js` Update the import in `.storybook/index.js` from `@storybook/react-native` to `@storybook/react-native/V6`. You can also change this file to be called `.storybook/index.tsx`. You should also make sure to add the storage prop to the getStorybookUI call. This lets you opt into using a different storage solution like mmkv or if you put async storage there it will continue to work as it did before. ```tsx // .storybook/index.tsx import './storybook.requires'; import { getStorybookUI } from '@storybook/react-native/V6'; import AsyncStorage from '@react-native-async-storage/async-storage'; const StorybookUIRoot = getStorybookUI({ storage: { getItem: AsyncStorage.getItem, setItem: AsyncStorage.setItem, }, }); export default StorybookUIRoot; ``` ### Update your stories Where ever you use storiesOf you should now import it from `@storybook/react-native/V6`. ```tsx import { storiesOf } from '@storybook/react-native/V6'; import { text } from '@storybook/addon-knobs'; import { withKnobs } from '@storybook/addon-ondevice-knobs'; import React from 'react'; import { Button } from './AnotherButton'; storiesOf('Another Button', module) .addDecorator(withKnobs) .add('another button example', () =>