Skip to content
This repository has been archived by the owner on Sep 10, 2022. It is now read-only.

How about a withPropTypes? #20

Closed
low-ghost opened this issue Oct 19, 2015 · 3 comments
Closed

How about a withPropTypes? #20

low-ghost opened this issue Oct 19, 2015 · 3 comments

Comments

@low-ghost
Copy link

great library! So, I had been doing prop types, at least with stateless functions, like so:

const component1 = (props) => <div {...props} />;

component1.propTypes = { ... };

export default component1;

Which looks ugly. Maybe it's even too simple for this lib, but a withPropTypes could look like

const withPropTypes = curry((propTypes, component) => component.propTypes = propTypes);

Would still support non-stateless components while fitting nicely in the final compose.

@low-ghost
Copy link
Author

Or actually... you'd have to create a new component to avoid mutating state and actually use the return value, right? Like:

const withPropTypes = curry((propTypes, BaseComponent) => React.createClass({
     propTypes,
     render() {
          return <BaseComponent {...this.props} />;
     }}));

@acdlite
Copy link
Owner

acdlite commented Oct 26, 2015

Good idea. In 0.6.0 I've added a set of static helpers, including one called setPropTypes(), which works essentially the same as the version in your original comment.

Since propTypes are only useful during development, I don't think it makes sense to wrap the base component in a new component, so this actually mutates the base component.

Thanks for the suggestion!

@acdlite acdlite closed this as completed Oct 26, 2015
@low-ghost
Copy link
Author

Awesome, the implementation looks great. Thanks!

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

No branches or pull requests

2 participants