Created
May 6, 2016 11:49
-
-
Save mbrochh/188e9b14713d4100fc7e90d455ff7b85 to your computer and use it in GitHub Desktop.
ReactJS propTypes composition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Component1 extends React.Component { | |
static propTypes = { | |
some: React.PropTypes.bool, | |
prop: React.PropTypes.string, | |
types: React.PropTypes.object, | |
} | |
} | |
class Component2 extends React.Component { | |
static propTypes = { | |
additional: React.PropTypes.object.isRequired, | |
some: React.PropTypes.bool, | |
prop: React.PropTypes.string, | |
types: React.PropTypes.object, | |
} | |
render() { | |
let { additional, ...other } = this.props | |
return ( | |
<Component1 {...other} /> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@erikras see, I'm still a JS syntax noob! That thing with the
...Component1.propTypes
is EXACTLY what I was hoping for! This is perfect, thank you so much!And I agree that Redux helps with propTypes-hell, just in my special usecase, I'm dealing with props that don't make sense to be stored in a reducer, so that's why I was asking.