Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StyledComponent ThemeProvider value working in canvas but causes error in Docs in react storybook with addon-docs #9789

Closed
ghost opened this issue Feb 7, 2020 · 3 comments

Comments

@ghost
Copy link

ghost commented Feb 7, 2020

Describe the bug
I have created react typescript app with Crate React App and integrated Storybook.

In the storybook preview.js:

import React, { Fragment } from 'react';
import { addDecorator } from '@storybook/react';
import { ThemeProvider } from 'styled-components';
import { GlobalStyle, theme } from '../src/theme';

addDecorator(story => (
  <ThemeProvider theme={theme}>
    <Fragment>
      <GlobalStyle />
      {story()}
    </Fragment>
  </ThemeProvider>
));

The component works fine in Canvas tab but gives error in Docs tab.

Screen Shot 2020-02-07 at 22 18 58

Screen Shot 2020-02-07 at 22 19 17

In Button.tsx

const Button = styled.button`
 background-color: ${props => props.theme.color.primary};
`;

In Docs tab, the theme object is undefined but works in Canvas tab. 

The issue occurs in Button.stories.mdx but does not occur if we create Button.stories.tsx file.

@shilman
Copy link
Member

shilman commented Feb 8, 2020

Can you show me Button.stories.tsx and Button.stories.mdx too?

@shilman
Copy link
Member

shilman commented Feb 8, 2020

Aha looks like you fixed it 👍

@ghost
Copy link
Author

ghost commented Feb 8, 2020

@shilman I reinstalled storybook and all storybook integrations from beginning and the error seems to be fixed.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant