react-helmet-async
react-helmet-async copied to clipboard
Error using library with Storybook
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>,
HelmetProvider needs to be added to the story as a decorator:
const storybook = storiesOf(storyGroupName, module)
.addDecorator(story => (
<HelmetProvider>
<Component>{story()}</Component>
</HelmetProvider>
));
FYI - in storybook 7, I could only get it to work in our lib monorepo by:
-
arranging peerDependencies as described here https://github.com/staylor/react-helmet-async/issues/27#issuecomment-422612330
-
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>
),
]
@raybooysen please close your issue.