Skip to content

Instantly share code, notes, and snippets.

@axelnormand
Created July 30, 2018 10:33
Show Gist options
  • Save axelnormand/3d8723f8566733089eab21015a1259fd to your computer and use it in GitHub Desktop.
Save axelnormand/3d8723f8566733089eab21015a1259fd to your computer and use it in GitHub Desktop.
React Native Stroybook
import { configure, getStorybookUI } from '@storybook/react-native';
import React from 'react';
import { getConfig } from 'src/config';
import {
allStories,
loadStories,
} from 'src/test/storybook/storyshots/allStories';
/**
* init storybook UI on app startup and returns component ready, but dont display yet
*/
export const initStorybookUI = (): React.ComponentType | null => {
if (!__DEV__) {
return null;
}
const PORT = 7007;
const HOST = getConfig().reactNativeHostIP || '';
console.log(
`Init Storybook with ${
allStories.length
} stories on http://${HOST}:${PORT.toString()}`,
);
// load the stories in
configure(() => {
loadStories();
}, module);
return getStorybookUI({
port: PORT,
onDeviceUI: false,
host: HOST,
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment