Created
August 11, 2018 02:42
-
-
Save Nicknyr/3154be7f02e388653063aeb644431819 to your computer and use it in GitHub Desktop.
React pass state to child component as a prop - FreeCodeCamp example
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
class MyApp extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
name: 'CamperBot' | |
} | |
} | |
render() { | |
return ( | |
<div> | |
<Navbar name={this.state.name} /> | |
</div> | |
); | |
} | |
}; | |
class Navbar extends React.Component { | |
constructor(props) { | |
super(props); | |
} | |
render() { | |
return ( | |
<div> | |
<h1>Hello, my name is: {this.props.name}</h1> | |
</div> | |
); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment