diff --git a/storybook-addon-export-to-codesandbox/src/withCodeSandboxButton.ts b/storybook-addon-export-to-codesandbox/src/withCodeSandboxButton.ts index 170361e..29e6153 100644 --- a/storybook-addon-export-to-codesandbox/src/withCodeSandboxButton.ts +++ b/storybook-addon-export-to-codesandbox/src/withCodeSandboxButton.ts @@ -5,11 +5,11 @@ import { getDependencies } from './getDepdencies'; import type { PackageDependencies } from './getDepdencies'; export const withCodeSandboxButton: StoryWrapper = (StoryFn: StoryFunction, context: StoryContext) => { - if (context.viewMode === 'docs') { - useEffect(() => { + useEffect(() => { + if (context.viewMode === 'docs') { displayToolState(`#anchor--${context.id} .docs-story`, context); - }); - } + } + }, [context]); return StoryFn(context); };