Skip to content

Instantly share code, notes, and snippets.

@vtno
Created March 29, 2017 09:17
Show Gist options
  • Save vtno/be6c6778fb3bfc779648caa50a53c0a8 to your computer and use it in GitHub Desktop.
Save vtno/be6c6778fb3bfc779648caa50a53c0a8 to your computer and use it in GitHub Desktop.
Passing new props to this.props.children
export default Class {
constructor(props) {
this.state = {
userRole: 'doctor'
}
}
render(){
const childrenWithProps = React.Children.map(this.props.children,
(child) => React.cloneElement(child, {
userRole: this.state.userRole,
name: this.stae.name
})
)
return childrenWithProps
}
}
// Another File
class Children {
props {
userRole: String
}
renderA = () => {
return <div>this.prop.name</div>
}
render() {
if (this.props.userRole) {
return this.renderA()
} else {
return this.renderB()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment