Created
March 29, 2017 09:17
-
-
Save vtno/be6c6778fb3bfc779648caa50a53c0a8 to your computer and use it in GitHub Desktop.
Passing new props to this.props.children
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
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