diff --git a/app/react-native/src/preview/Preview.tsx b/app/react-native/src/preview/Preview.tsx index 7572835679..3a04383dac 100644 --- a/app/react-native/src/preview/Preview.tsx +++ b/app/react-native/src/preview/Preview.tsx @@ -84,12 +84,13 @@ export default class Preview { ); } - const { initialSelection, shouldPersistSelection } = params; - this._setInitialStory(initialSelection, shouldPersistSelection); if (params.asyncStorage) { this._asyncStorage = params.asyncStorage; } + const { initialSelection, shouldPersistSelection } = params; + this._setInitialStory(initialSelection, shouldPersistSelection); + this._channel.on(Events.SET_CURRENT_STORY, (d: { storyId: string }) => { this._selectStoryEvent(d); }); @@ -169,6 +170,7 @@ export default class Preview { _selectStory(story: any) { this._storyStore.setSelection({ storyId: story.id, viewMode: 'story' }); + this._channel.emit(Events.SELECT_STORY, story); } _checkStory(storyId: string) { diff --git a/app/react-native/src/preview/components/OnDeviceUI/OnDeviceUI.tsx b/app/react-native/src/preview/components/OnDeviceUI/OnDeviceUI.tsx index 04741e0991..8d0dc867cf 100644 --- a/app/react-native/src/preview/components/OnDeviceUI/OnDeviceUI.tsx +++ b/app/react-native/src/preview/components/OnDeviceUI/OnDeviceUI.tsx @@ -76,16 +76,15 @@ const useSelectedStory = (storyStore: StoryStore) => { const channel = useRef(addons.getChannel()); useEffect(() => { - const handleStoryWasSet = ({ storyId: newStoryId }: { storyId: string }) => - setStoryId(newStoryId); + const handleStoryWasSet = ({ id: newStoryId }: { id: string }) => setStoryId(newStoryId); const currentChannel = channel.current; - channel.current.on(Events.SET_CURRENT_STORY, handleStoryWasSet); + channel.current.on(Events.SELECT_STORY, handleStoryWasSet); //TODO: update preview without force channel.current.on(Events.FORCE_RE_RENDER, forceUpdate); return () => { - currentChannel.removeListener(Events.SET_CURRENT_STORY, handleStoryWasSet); + currentChannel.removeListener(Events.SELECT_STORY, handleStoryWasSet); currentChannel.removeListener(Events.FORCE_RE_RENDER, forceUpdate); }; }, []);