Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. export default Class {
  2. constructor(props) {
  3. this.state = {
  4. userRole: 'doctor'
  5. }
  6. }
  7.  
  8. render(){
  9.  
  10. const childrenWithProps = React.Children.map(this.props.children,
  11. (child) => React.cloneElement(child, {
  12. userRole: this.state.userRole,
  13. name: this.stae.name
  14. })
  15. )
  16. return childrenWithProps
  17. }
  18. }
  19. // Another File
  20. class Children {
  21. props {
  22. userRole: String
  23. }
  24.  
  25. renderA = () => {
  26. return <div>this.prop.name</div>
  27. }
  28.  
  29. render() {
  30. if (this.props.userRole) {
  31. return this.renderA()
  32. } else {
  33. return this.renderB()
  34. }
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement