Describe the bug
Calling addDecorator(withKnobs) on a story or in the global config causes the app the throw a "decorator is not a function" error when trying to render the component.
Indeed, withKnobs is undefined after importing like so:
import { withKnobs } from '@storybook/addon-ondevice-knobs';
withKnobs does not appear to be a valid import:

withKnobs is not exported from the package's index.js.
When I don't call addDecorator(withKnobs), Storybook runs fine and I do see the empty "KNOBS" tab appear in the device UI.
To Reproduce
react-native run-ios in storybook mode. (This is an ejected app, not Expo)Expected behavior
The storybook component should render without throwing an error and the knobs panel should populate in the addons tab.
Screenshots

Code snippets
import { AppRegistry } from 'react-native';
import Config from 'react-native-config';
import { getStorybookUI, configure } from '@storybook/react-native';
import SplashScreen from 'react-native-smart-splash-screen';
import './rn-addons';
import './config';
configure(() => {
require('./stories');
}, module);
const StorybookUIRoot = getStorybookUI({
onDeviceUI: true,
});
if (Config.ENABLE_STORYBOOK) {
SplashScreen.close({
animationType: SplashScreen.animationType.fade,
duration: 850,
});
AppRegistry.registerComponent('MyApp', () => StorybookUIRoot);
}
export default StorybookUIRoot;
import '@storybook/addon-ondevice-knobs/register';
import '@storybook/addon-ondevice-backgrounds/register';
import '@storybook/addon-ondevice-notes/register';
import { addDecorator } from '@storybook/react-native';
import { withBackgrounds } from '@storybook/addon-ondevice-backgrounds';
import { withNotes } from '@storybook/addon-ondevice-notes';
import { withKnobs } from '@storybook/addon-ondevice-knobs';
import { COLOR_WHITE, COLOR_BLACKER, COLOR_PRIMARY_DARK } from 'app/src/styles/colors';
addDecorator(withKnobs);
addDecorator(
withBackgrounds([
{ name: 'white', value: COLOR_WHITE, default: true },
{ name: 'teal', value: COLOR_PRIMARY_DARK },
{ name: 'black', value: COLOR_BLACKER },
]),
);
import React from 'react';
import { storiesOf } from '@storybook/react-native';
import ActivityIndicatorView from 'app/src/components/ActivityIndicatorView/ActivityIndicatorView';
storiesOf('ActivityIndicatorView', module)
.add('default', () => <ActivityIndicatorView />);
System:
Additional context
Add any other context about the problem here.
So, I just noticed when running yarn install that addon-ondevice-knobs has a peer dependency on addon-knobs. After installing that, other thing I had to change was to import from '@storybook/addon-knobs' instead of from '@storybook/addon-ondevice-knobs'.
It may just be me, but it seems a bit unintuitive to import the decorator and types from addon-knobs instead of addon-ondevice-knobs. That is not the pattern followed with the other ondevice-* packages, which tell you to import from the ondevice version of the package.
It might be worth making this explicit in the ondevice-knobs readme, which is quite sparse. I'm happy to take a stab at that if it's acceptable.
@stevula would love to review a PR for that. @Gongreg maybe you can chime in here too?
Hey,
I definitely agree that the documentation could be a lot better over there. The addon was done as a POC that we can support addons in React Native. And it used addon-knobs to reuse as much code as possible.
@stevula, if you have any time to update readme, that would be great.
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks!
@Gongreg
@shilman
Oh, exactly the same thing happened to me. And I agree.
If I have times, I'll fixed the readme and send PR.
@Gongreg
@shilman
What do you think?
https://github.com/storybooks/storybook/pull/5629
I noticed that import is natural in other 'ondevice' packages ....
Should be unified so that it can be used with *-ondevice-* import?
import { withBackgrounds } from '@storybook/addon-ondevice-backgrounds';
import { withNotes } from '@storybook/addon-ondevice-notes';
@nitaking Thanks for fixing this! What do you mean by unified though?
Yowza!! I just released https://github.com/storybooks/storybook/releases/tag/v4.1.13 containing PR #5629 that references this issue. Upgrade today to try it out!
Closing this issue. Please re-open if you think there's still more to do.
Most helpful comment
So, I just noticed when running
yarn installthataddon-ondevice-knobshas a peer dependency onaddon-knobs. After installing that, other thing I had to change was to import from'@storybook/addon-knobs'instead of from'@storybook/addon-ondevice-knobs'.It may just be me, but it seems a bit unintuitive to import the decorator and types from
addon-knobsinstead ofaddon-ondevice-knobs. That is not the pattern followed with the otherondevice-*packages, which tell you to import from the ondevice version of the package.It might be worth making this explicit in the ondevice-knobs readme, which is quite sparse. I'm happy to take a stab at that if it's acceptable.