@storybook-test: more streamlined and powerful testingVisual test with Chromatic
Back to Intro to Storybook
  • Get started
  • Simple component
  • Composite component
  • Data
  • Conclusion
  • Contribute

Storybook for React Native tutorial

Set up Storybook in your development environment
This community translation has not been updated to the latest version of Storybook yet. Help us update it by applying the changes in the English guide to this translation. Pull requests are welcome.

Storybook helps you build UI components isolated from the business logic and context of your app. This edition of the Intro to Storybook tutorial is for React Native; other editions exist for ReactVueAngularSvelte and Ember.

Storybook and your app

Set Up React Native Storybook

We’ll need to follow a few steps to get started. In this tutorial we'll be using this template where we've already setup a React Native app using Expo and added Storybook the project.

Before we get started, there are some things we’ll need to consider:

  • To help you throughout the tutorial, you’ll need a phone or a simulator already configured to allow you to run the application. For more information see the Expo documentation on running on IOS and Android.
  • This tutorial will be focused on IOS/Android. React Native can target other platforms that this tutorial won't cover.
  • You’ll also need nodejs configured on your machine.

First download the template we've created for this tutorial.

npx degit chromaui/intro-storybook-react-native-template#main taskbox

Next, let's install the dependencies and run the app to make sure everything is working as expected.

cd taskbox
yarn install

Now you have the app lets run it to make sure everything is working as expected.

You can pick ios or android and run either and make sure the app is working.

# Run the application on IOS
yarn ios

# Run the application on Android
yarn android

# Run Storybook on ios
yarn storybook:ios

# Run Storybook on android
yarn storybook:android

💡 Throughout this tutorial, Yarn will be used. If you're following along this tutorial but don't have it configured, you can easily swap out the commands to match your package manager of choice (e.g., npm, pnpm).

When running the application with yarn ios you should see this rendered on the device:

expo starter screen

When running Storybook with yarn storybook:ios you should see this:

Storybook UI

How it works

When initialized the template already provides the required configuration to help us get started developing our application with React Native. Before we start to build our UI from the ground up, let's take a moment and see how Storybook functions inside a React Native application and whats different.

Storybook in React Native is a component that you can render in your app, as opposed to other framework versions where Storybook runs on its own.

Because of this distinction we need a way to switch between the app and Storybook. To do this we use environment variables, and we'll go over that quickly now.

💡 See the expo documentation for more details on how to use environment variables.

In our project there is a configuration file for expo called app.config.js this file is where we configure things like our app name and constants that we can use throughout the app.

In this file we set the storybookEnabled constant to the value of the environment variable STORYBOOK_ENABLED which we'll go over shortly.

export default ({ config }) => ({
  name: "Storybook Tutorial Template",
  slug: "storybook-tutorial-template",
  extra: {
    storybookEnabled: process.env.STORYBOOK_ENABLED,

This lets us access the storybookEnabled variable in our app using the expo-constants package and we use this to determine whether we render Storybook or your app.

import Constants from 'expo-constants';

function App() {
  // ... removed for brevity

// Default to rendering your app
let AppEntryPoint = App;

// Render Storybook if storybookEnabled is true
if (Constants.expoConfig.extra.storybookEnabled === 'true') {
  AppEntryPoint = require('./.storybook').default;

export default AppEntryPoint;

In package.json we see a few Storybook scripts. We use these to pass that environment variable to our app and run some setup.

"scripts": {
  "storybook": "sb-rn-get-stories && STORYBOOK_ENABLED='true' expo start",
  "storybook:ios": "sb-rn-get-stories && STORYBOOK_ENABLED='true' expo ios",
  "storybook:android": "sb-rn-get-stories && STORYBOOK_ENABLED='true' expo android"

This is where our STORYBOOK_ENABLED environment variable is set to true, which then tells our app to render Storybook instead of our app.

💡 There are other ways to configure Storybook, this is just the simplest way to get started.

Commit changes

At this stage it's safe to add our files to a local repository. Run the following commands to initialize a local repository, add and commit the changes we've done so far.

git init

Followed by:

git add .


git commit -m "first commit"

And finally:

git branch -M main

Let's start building our first component!

Is this free guide helping you? Tweet to give kudos and help other devs find it.
Next Chapter
Simple component
Build a simple component in isolation
✍️ Edit on GitHub – PRs welcome!
Join the community
6,376 developers and counting
WhyWhy StorybookComponent-driven UI
Open source software

Maintained by
Special thanks to Netlify and CircleCI