Loading...
Loading...
Set up Storybook for React Native in Expo, React Native CLI, or Re.Pack projects. Use when adding Storybook to a project, configuring metro.config.js with withStorybook, creating .rnstorybook configuration files, setting up Storybook routes in Expo Router, configuring getStorybookUI, or adding the StorybookPlugin to a Re.Pack rspack/webpack config. Covers Expo, Expo Router, plain React Native CLI, and Re.Pack setups.
npx skill4agent add storybookjs/react-native setup-react-native-storybook@storybook/react-nativeyarn.lockpnpm-lock.yamlbun.lockbnpmnpmyarn addnpm installyarn storybooknpm run storybooknpx expo installbunx expo install<pm> create storybook--npxbunxrspack.configwebpack.config@callstack/repackapp/_layout.tsxexpo-router@react-native-community/clinpm create storybook -- --type react_native --yes
# or: pnpm create storybook --type react_native --yes
# or: bun create storybook --type react_native --yes.rnstorybook/main.tspreview.tsxindex.tsx.rnstorybook/index.tsx// .rnstorybook/index.tsx
import AsyncStorage from '@react-native-async-storage/async-storage';
import { view } from './storybook.requires';
const StorybookUIRoot = view.getStorybookUI({
storage: {
getItem: AsyncStorage.getItem,
setItem: AsyncStorage.setItem,
},
enableWebsockets: true,
});
export default StorybookUIRoot;@react-native-async-storage/async-storagenpm install @react-native-async-storage/async-storagestories.rnstorybook/main.tscomponents/src/components/src/ui/// .rnstorybook/main.ts
const main: StorybookConfig = {
stories: [
'./stories/**/*.stories.?(ts|tsx|js|jsx)', // example stories from init
'../src/components/**/*.stories.?(ts|tsx|js|jsx)', // add based on project structure
],
// ...
};withStorybookStorybookPluginnpm run start
npm run ios # or npm run androidmodule.exports = withStorybook(config, {
enabled: true, // Remove Storybook from bundle when false
configPath: './.rnstorybook', // Storybook config directory
useJs: false, // Generate .js instead of .ts
docTools: true, // Auto arg extraction
liteMode: false, // Mock default UI deps (use with react-native-ui-lite)
websockets: { port: 7007, host: 'localhost' }, // Remote control
});new StorybookPlugin({
enabled: true, // Strip Storybook from bundle when false
configPath: './.rnstorybook', // Storybook config directory
useJs: false, // Generate .js instead of .ts
docTools: true, // Auto arg extraction
liteMode: false, // Mock default UI deps (use with react-native-ui-lite)
websockets: 'auto', // 'auto' detects LAN IP, or { port: 7007, host: 'localhost' }
});