Skip to content
This repository has been archived by the owner on Nov 10, 2017. It is now read-only.

Latest commit

 

History

History
71 lines (55 loc) · 1.54 KB

manual-setup.md

File metadata and controls

71 lines (55 loc) · 1.54 KB

Manual Setup

First, install the @kadira/react-native-storybook module

npm i -D @kadira/react-native-storybook

Create a new directory called storybook in your project root and create an entry file (index.ios.js or index.android.js) as given below. (Don't forget to replace "MyApplicationName" with your app name).

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

// import your stories
configure(function() {
  require('./stories');
}, module);

const StorybookUI = getStorybookUI({port: 7007, host: 'localhost'});
AppRegistry.registerComponent('MyApplicationName', () => StorybookUI);

Create a file named addons.js file in storybook directory to use default set of addons.

import '@kadira/react-native-storybook/addons';

Then write your first story in the stories directory like this:

// index.js

import React from 'react';
import { storiesOf } from '@kadira/react-native-storybook';
import { View, Text } from 'react-native';

const style = {
  flex: 1,
  justifyContent: 'center',
  alignItems: 'center',
  backgroundColor: '#F5FCFF'
};

const CenteredView = (props) => (
  <View style={style}>
    {props.children}
  </View>
);

storiesOf('CenteredView')
  .add('default view', () => (
    <CenteredView>
      <Text>Hello Storybook</Text>
    </CenteredView>
  ));

Then add following NPM script into your package.json file:

{
  "scripts": {
    ...
    "storybook": "storybook start -p 7007"
    ...
  }
}