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

defaultProps weird issue when used in storybook #13661

Closed
ErAz7 opened this issue Jan 16, 2021 · 2 comments
Closed

defaultProps weird issue when used in storybook #13661

ErAz7 opened this issue Jan 16, 2021 · 2 comments

Comments

@ErAz7
Copy link

ErAz7 commented Jan 16, 2021

Describe the bug

when I use an object in defaultProps, object name is stored in default prop as an string instead of object value

To Reproduce

here is a very simple example:

  1. create this component which imports Theme from config.js, sets theme prop's default value to THEMES.PRIMARY and just renders theme:
import PropTypes from 'prop-types';
import React, { PureComponent } from 'react';
import { THEMES } from 'config';

export default class MyComponent extends PureComponent {
    static propTypes = {
        theme: PropTypes.string
    }

    static defaultProps = {
        theme: THEMES.PRIMARY
    }

    render() {
        const { theme } = this.props;

        return (
            <div>
                {theme}
            </div>
        );
    }
}

and here is config.js:

export const THEMES = {
    PRIMARY: 'primary'
};
  1. create the story file:
import React from 'react';
import MyComponent from './MyComponent';

export default {
    component: MyComponent,
    title: 'components/MyComponent'
};

const Template = args => <MyComponent {...args} />;

export const Playground = Template.bind({});
  1. now if you run yarn storybook and check the story, you'll see this:
    2021-01-16_19-33-23
    as you see, "THEMES.PRIMARY" is stored in theme instead of "primary" which is the value of THEMES.PRIMARY

I think the cause for this is related to this issue, except this will result in more serious problems

@pixelass
Copy link

pixelass commented Mar 4, 2021

Duplicate: There is an open issue for this: #12076

@shilman
Copy link
Member

shilman commented Mar 5, 2021

closing as dupe to #12076

@shilman shilman closed this as completed Mar 5, 2021
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

3 participants