Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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()
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement