Skip to content

defaultProps provided with Object spread are not generated #404

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

Closed
patricklafrance opened this issue Nov 25, 2019 · 2 comments · Fixed by #415
Closed

defaultProps provided with Object spread are not generated #404

patricklafrance opened this issue Nov 25, 2019 · 2 comments · Fixed by #415

Comments

@patricklafrance
Copy link

patricklafrance commented Nov 25, 2019

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

@danez
Copy link
Collaborator

danez commented Jan 4, 2020

This will be fixed in the next version. Thanks for reporting.

@patricklafrance
Copy link
Author

@shilman 🥳🥳

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants