-
Notifications
You must be signed in to change notification settings - Fork 27
Using knobs in global decorators #31
Comments
Yeah, the knob store is not created because story here is not decorated with the import { withKnobs, select } from '@kadira/storybook-addon-knobs';
addDecorator((story, context) => {
const storyWithKnobs = withKnobs(story, context) // explicitly add withKnobs
return (
<ThemeProvider theme={select('Theme', ['Light', 'Dark'], 'Light')}>
{storyWithKnobs}
</ThemeProvider >
);
}
); This explicitly adds |
Or this way which looks slightly cleaner. addDecorator(withKnobs) // add withKnobs
addDecorator((story) => {
const content = story() // call story early so knob store is created before `select` call
return (
<ThemeProvider theme={select('Theme', themes, 'Light')}>
{content}
</ThemeProvider >
);
}
); |
HI @roonyh, thanks!. This works on rendering the knob correctly but for some reason when I switch the theme it does not trigger a prop change. I'll try to dig to see if my code is missing something. Btw, the url does change, I just think there is no render being triggered as when I refresh the page the new selected value is applied. |
Confirmed, I can switch the theme using the react dev tools but not with the knobs, it might be because it's out of context? |
After further research I found that it does call forceUpdate but on the WrapStory component but the decorator is outside this scope so it does not get updated. So proper way to implement this was to add the decorator and then add knobs like so:
|
This is more like a question but I have a use case in which I would like to use knobs at the global decorator level, so I added the following code to my
config.js
like this:The above code fails on this error becuase I think because the knob store is not been created yet:
The text was updated successfully, but these errors were encountered: