Storybook: [API] storybook api onchange returns undefined kind

Created on 8 Aug 2019  路  3Comments  路  Source: storybookjs/storybook

Describe the bug
When calling storybookAPI.onChange((kind,story) => as specified in the docs, story is undefined.

To Reproduce
Steps to reproduce the behavior:

import addonAPI from '@storybook/addons';
addonAPI.register('test', storybookAPI => {
    storybookAPI.on((kind, story) => {
                console.log(kind); // returns the story id, e.g. components--action-button
        console.log(story); // returns undefined
    });
});

Expected behavior
kind should be the component type, story should be the story name.

System:
Environment Info:

System:
OS: macOS 10.14.5
CPU: (4) x64 Intel(R) Core(TM) i5-5287U CPU @ 2.90GHz
Binaries:
Node: 12.6.0 - /usr/local/bin/node
Yarn: 1.16.0 - /usr/local/bin/yarn
npm: 6.9.0 - /usr/local/bin/npm
Browsers:
Chrome: 76.0.3809.100
Firefox: 67.0.2
Safari: 12.1.1
npmPackages:
@storybook/react: ^5.2.0-alpha.36 => 5.2.0-beta.25

Additional context
I'm on the new storybook with addon-docs, maybe something got changed there that isn't in the docs yet?

addons question / support

All 3 comments

storybookAPI.onChange doesn't exist AFAIK
storybookAPI.on requires an eventType and a handler
storybookAPI.onStory is deprecated in favour of:

import { STORY_CHANGED } from '@storybook/core-events';

addons.register('my-organisation/my-addon', api => {
  api.on(STORY_CHANGED, storyId => console.log(storyId));
});

Please let us know if you're still experiencing problems.

This should be added to the documentation where deprecated info onStory is shown.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rpersaud picture rpersaud  路  3Comments

miljan-aleksic picture miljan-aleksic  路  3Comments

MrOrz picture MrOrz  路  3Comments

sakulstra picture sakulstra  路  3Comments

levithomason picture levithomason  路  3Comments