Skip to content

Instantly share code, notes, and snippets.

@mbrochh
Created May 6, 2016 11:49
Show Gist options
  • Save mbrochh/188e9b14713d4100fc7e90d455ff7b85 to your computer and use it in GitHub Desktop.
Save mbrochh/188e9b14713d4100fc7e90d455ff7b85 to your computer and use it in GitHub Desktop.
ReactJS propTypes composition
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} />
)
}
}
@mbrochh
Copy link
Author

mbrochh commented May 7, 2016

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment