Skip to content

defaultProps provided with Object spread are not generated #404

Closed
@patricklafrance

Description

@patricklafrance

Hi,

I am trying to understand why the following doesn't work. The defaultValue for hey and oh is undefined.

const TO_SPREAD = {
    hey: "ho!"
}

export const MyComponent = ({ text }) => {
    return <div>{text}</div>
};
MyComponent.propTypes = {
    text: PropTypes.string,
    hey: PropTypes.string,
    oh: PropTypes.string,
};
MyComponent.defaultProps = {
    text: "Hey!",
    ...TO_SPREAD
};

MyComponent.defaultProps.oh = "foo!";

I get the following result:

{
  "description": "",
  "displayName": "MyComponent",
  "methods": [],
  "props": {
    "text": {
      "type": {
        "name": "string"
      },
      "required": false,
      "description": "",
      "defaultValue": {
        "value": "\"Hey!\"",
        "computed": false
      }
    },
    "hey": {
      "type": {
        "name": "string"
      },
      "required": false,
      "description": ""
    },
    "oh": {
      "type": {
        "name": "string"
      },
      "required": false,
      "description": ""
    }
  }
}

Thank you,

Patrick

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions