Skip to content

Incorrect default value inferring for stateless components #131

@arunoda

Description

@arunoda

This issue came with the version 2.12.0.
And we got this while working with our babel plugin for doc gen.

Assume we've a stateless component like this:

const Button = ({ children, onClick, style = {} }) => (
  <button
    style={{ }}
    onClick={onClick}
  >
    {children}
  </button>
);

Button.propTypes = {
  children: React.PropTypes.string.isRequired,
  onClick: React.PropTypes.func,
  style: React.PropTypes.object,
};

export default Button;

Then generated info like this:

{
  description: '',
  props: {
    children: {
      type: {
        name: 'string'
      },
      required: true,
      description: '',
      defaultValue: {
        value: 'children',
        computed: true
      }
    },
    onClick: {
      type: {
        name: 'func'
      },
      required: false,
      description: '',
      defaultValue: {
        value: 'onClick',
        computed: true
      }
    },
    style: {
      type: {
        name: 'object'
      },
      required: false,
      description: '',
      defaultValue: {
        value: '{}',
        computed: false
      }
    }
  }
}

Just look at the default values for onClick or children.
This doesn't seems to be correct to me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions