diff --git a/packages/react-native-storybook/src/getStorybook/hooks/useStoryEmitter.ts b/packages/react-native-storybook/src/getStorybook/hooks/useStoryEmitter.ts index 8f5672a0..6d69ce9b 100644 --- a/packages/react-native-storybook/src/getStorybook/hooks/useStoryEmitter.ts +++ b/packages/react-native-storybook/src/getStorybook/hooks/useStoryEmitter.ts @@ -1,5 +1,5 @@ import { useEffect } from 'react'; -import { getAddons } from '../utils/storybookImports'; +import { getAddons, SET_CURRENT_STORY } from '../utils/storybookImports'; function useStoryEmitter(updateRenderedStoryId: (storyId: string) => void): (id: string) => void { useEffect(() => { @@ -10,7 +10,7 @@ function useStoryEmitter(updateRenderedStoryId: (storyId: string) => void): (id: const initialize = async (): Promise => { const _channel = await getAddons().ready(); - _channel.on('setCurrentStory', handleStoryRendered); + _channel.on(SET_CURRENT_STORY, handleStoryRendered); }; setTimeout(() => initialize(), 500); @@ -19,9 +19,9 @@ function useStoryEmitter(updateRenderedStoryId: (storyId: string) => void): (id: return async (storyId: string) => { const _channel = await getAddons().ready(); - _channel.emit('setCurrentStory', { storyId }); + _channel.emit(SET_CURRENT_STORY, { storyId }); // if we don't call it twice going back from preview to original mode doesn't work - _channel.emit('setCurrentStory', { storyId }); + _channel.emit(SET_CURRENT_STORY, { storyId }); }; } diff --git a/packages/react-native-storybook/src/getStorybook/utils/storybookImports.ts b/packages/react-native-storybook/src/getStorybook/utils/storybookImports.ts index b1eac9c3..1f339672 100644 --- a/packages/react-native-storybook/src/getStorybook/utils/storybookImports.ts +++ b/packages/react-native-storybook/src/getStorybook/utils/storybookImports.ts @@ -13,3 +13,9 @@ try { } export const getAddons = (): any => addonsV8 ?? addonsV7; + +// This was originally imported from: +// - @storybook/core-events in Storybook 7 +// - @storybook/core/core-events in Storybook 8 +// We keep it hardcoded as some users didn't have dependency in their versions of the library. +export const SET_CURRENT_STORY = 'setCurrentStory';