Skip to content

Instantly share code, notes, and snippets.

@Nicknyr
Created August 11, 2018 02:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nicknyr/3154be7f02e388653063aeb644431819 to your computer and use it in GitHub Desktop.
Save Nicknyr/3154be7f02e388653063aeb644431819 to your computer and use it in GitHub Desktop.
React pass state to child component as a prop - FreeCodeCamp example
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