Manually set up Storybook without using the CLI for full control
This guide covers setting up Storybook manually without using the CLI. This is useful if you want full control over the setup process or if the CLI doesn’t work for your specific project configuration.
You can use any package manager (npm, yarn, or pnpm) throughout this guide.
The withStorybook function automatically generates the storybook.requires.ts file when you run your app, but this script is useful for manual generation.
8
Render Storybook
Update your app to render the Storybook component. The simplest approach is to export Storybook from your app entry point:
App.tsx
import StorybookUI from './.rnstorybook';export default StorybookUI;
For conditional rendering based on environment variables:
App.tsx
import { View, Text } from 'react-native';import Constants from 'expo-constants';function App() { return ( <View style={styles.container}> <Text>Open up App.tsx to start working on your app!</Text> </View> );}let AppEntryPoint = App;if (Constants.expoConfig?.extra?.storybookEnabled === 'true') { AppEntryPoint = require('./.rnstorybook').default;}export default AppEntryPoint;
9
Run Storybook
Run your app as normal:
npm run startnpm run ios # or npm run android
If you’re using an environment variable to enable Storybook, add convenience scripts: