question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"decorator is not a function" error when using withKnobs decorator from addon-ondevice-knobs (React Native)

See original GitHub issue

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: screen shot 2018-11-23 at 5 44 00 pm

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

  1. See code snippets below and run 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

simulator screen shot - iphone 7 - 2018-11-23 at 17 01 53

Code snippets

storybook/index.js
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;
storybook/rn-addons.js
import '@storybook/addon-ondevice-knobs/register';
import '@storybook/addon-ondevice-backgrounds/register';
import '@storybook/addon-ondevice-notes/register';
storybook/config.js
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 },
  ]),
);
Example story:
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:

  • OS: iOS (Simulator)
  • Device: Macbook Pro 2018
  • Browser: n/a
  • Framework: React Native
  • Addons: addon-ondevice-knobs, addon-ondevice-backgrounds, addon-ondevice-notes
  • Version: 4.0.8 (also tried 4.1.0-alpha.7, 4.0.0-alpha.25)

Additional context Add any other context about the problem here.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
stevulacommented, Nov 24, 2018

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.

1reaction
nitakingcommented, Feb 15, 2019

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

react storybook addon knobs not showing - Stack Overflow
I cant seem to be getting the @storybook addon knobs working? It doesnt seem to be decorating the actual story ...
Read more >
@storybook/addon-knobs - npm
Start using @storybook/addon-knobs in your project by running `npm i ... decorators: [withKnobs], }; // Add the `withKnobs` decorator to add ...
Read more >
with-knobs Addon | Storybook: Frontend workshop for UI ...
Import `withKnobs` as default from `'with-knobs'` and use it to wrap an arbitrary ... addDecorator } from '@storybook/react'; import { withKnobs } from ......
Read more >
React Storybook Tutorial - 10 - Knobs Addon - YouTube
... + Facebook - https://www.facebook.com/codevolutionweb Business - codevolution.business@gmail.com Knobs Addon with Storybook and React ...
Read more >
Simple Example of Storybook with React, With Knobs, With ...
js ] inside the stories folder and you need to import component you want to make the story of as shown below. //Button.stories.js...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found