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 #1

Open
Frikki opened this issue May 7, 2015 · 6 comments
Open

DefaultProps #1

Frikki opened this issue May 7, 2015 · 6 comments

Comments

@Frikki
Copy link

Frikki commented May 7, 2015

How can you specify defaultProps on the ownee class?

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/13446506-defaultprops?utm_campaign=plugin&utm_content=tracker%2F16182690&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F16182690&utm_medium=issues&utm_source=github).
@koistya
Copy link
Member

koistya commented May 7, 2015

Decorators hide static properties..

@Frikki
Copy link
Author

Frikki commented May 7, 2015

Sorry, but I don’t understand your answer. I’d like to know how I can define propTypes and defaultProps on the component that is being decorated?

@koistya
Copy link
Member

koistya commented May 7, 2015

In general you define default properties and their types like so:

class MyComponent {

  static propTypes: {
    message: PropTypes.string.isRequired
  };

  static defaultProps: {
    message: 'Welcome!'
  };

  render() {
    return <div>{this.props.message}</div>;
  }
}

...but the problem is, if you wrap this class into a higher-level component, HOC will hide static properties of the ownee class.

@Frikki
Copy link
Author

Frikki commented May 7, 2015

Does that mean that it is useless to have propTypes and defaultProps defined on the ownee class? And how can we work around this without too much hacking? After all, the checks on propTypes and default provided values are quite important in many cases.

@sandeepone
Copy link

@Frikki Got any solution for accessing the props?? Any work around

@iegik
Copy link

iegik commented Nov 13, 2017

class MyComponent {
  props: {
    message: 'Welcome!'
  };
}

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

No branches or pull requests

4 participants