react-helmet-async icon indicating copy to clipboard operation
react-helmet-async copied to clipboard

Error using library with Storybook

Open raybooysen opened this issue 6 years ago • 1 comments

I'm not sure if this related to the fact that storybook/components uses react-helmet-async, but I'm seeing the error "Cannot read property 'add' of undefined" on hot-reloads only in storybooks.

My code looks like this:

<Provider store={store}>
    <HelmetProvider context={helmetContext}>
        <MainRoute />
    </HelmetProvider>
</Provider>,

raybooysen avatar Apr 11 '19 09:04 raybooysen

HelmetProvider needs to be added to the story as a decorator:

const storybook = storiesOf(storyGroupName, module)
    .addDecorator(story => (
        <HelmetProvider>
            <Component>{story()}</Component>
        </HelmetProvider>
    ));

fedecarg avatar Apr 24 '19 12:04 fedecarg

FYI - in storybook 7, I could only get it to work in our lib monorepo by:

  1. arranging peerDependencies as described here https://github.com/staylor/react-helmet-async/issues/27#issuecomment-422612330

  2. making it the absolute first decorator (alone, not combined with any other) in the preview.tsx

export const decorators = [
  // UGH - this is required to get helmet to work with storybook and it must be the _first_ decorator (and alone it appears)
  (StoryFn) => (
    <HelmetProvider context={helmetContext}>
      <StoryFn />
    </HelmetProvider>
  ),
  (StoryFn) => (
    <ThemeProvider theme={convert(themes.light)}>
      <StoryFn />
    </ThemeProvider>
  ),
]

rosskevin avatar May 12 '23 20:05 rosskevin

@raybooysen please close your issue.

rosskevin avatar May 12 '23 20:05 rosskevin