Listen to Storybook events in preview.ts in Storybook 8 #28407
-
SummaryIn Storybook 7 I could do in preview.ts the following:
But addons package is deprecated Tried this:
But it doesn't reach to callback for event listener... How to do it in Storybook 8? Additional informationNo response Create a reproductionNo response |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I just had a very similar problem when debugging something in the a11y addon. I was trying to use When digging into the a11y addon's code to see how it was accessing and using the channel, I found it was importing addons from import { addons } from '@storybook/preview-api'; and now everything works how I expected it to! For example: channel.on('storybook/a11y/result', (data) => {
console.log('A11y result', data);
}) As per your example, I also tested core events, and they also work. For example: import { addons } from '@storybook/preview-api';
import { STORY_RENDERED } from '@storybook/core-events';
const channel = addons.getChannel();
channel.on(STORY_RENDERED, () => {
console.log('Story rendered');
}); |
Beta Was this translation helpful? Give feedback.
I just had a very similar problem when debugging something in the a11y addon. I was trying to use
channel.on()
to detect events, but it was only picking up events I emitted myself. I had tried importing both via@storybook/addons
and@storybook/manager-api
, neither worked.When digging into the a11y addon's code to see how it was accessing and using the channel, I found it was importing addons from
storybook/internal/preview-api
. I updated my code to import addons like so:and now everything works how I expected it to! For example:
As per your example, …