Giter VIP home page Giter VIP logo

react-native-storybook-example's Introduction

storybook-example

This repo has the basic setup for storybook that is a amazing tool for less error prone apps with react-native. I decided to create it so I can reuse it later in future projects.

My code following the guide by Spencer Carli.

Link to the guide: https://www.reactnativeschool.com/building-a-component-library/configure-storybook

Add Dependency

After basic react-native app setup you need the storybook lib:

npx -p @storybook/cli sb init 

This will install and init storybook with its standard boilerplate code.

After that export a component from your app to storybook, i.e the App.js:

export default from '../storybook';

Running first time

Probably now you have a new folder with some sample code for storybook. Time for running! Now run the command to start storybook:

yarn storybook

This will start a local server in http://localhost:7007, after running your app check this, will probably have a button as an example.

Autoloading stories

Install react-native-storybook-loader for autoloading:

yarn react-native-storybook-loader -D

Add to your package.json the following setup:

  1. Add a script with:
"prestorybook": "rnstl"

And a configuration where the stories folder is where ROOT_DIR is the root path to the folder where the stories folder is located.

 "config": {
    "react-native-storybook-loader": {
      "searchDir":  [
        "./$ROOT_DIR"
      ],
      "pattern": "**/*.stories.js"
    }
  }

The index of your storybook folder need to look like these:

import { AppRegistry } from 'react-native';
import { getStorybookUI, configure } from '@storybook/react-native';
import { loadStories } from './storyLoader';
import './rn-addons';

// import stories
configure(() => {
  // Loading stories HERE!!
  loadStories();
}, module);

const StorybookUIRoot = getStorybookUI({});

AppRegistry.registerComponent('%APP_NAME%', () => StorybookUIRoot);

export default StorybookUIRoot;

react-native-storybook-example's People

Contributors

vinipachecov avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.