Skip to content

Instantly share code, notes, and snippets.

@maecapozzi
Last active August 14, 2018 13:41
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 maecapozzi/a7b44016cf440ce688f15084846fcbf9 to your computer and use it in GitHub Desktop.
Save maecapozzi/a7b44016cf440ce688f15084846fcbf9 to your computer and use it in GitHub Desktop.
Basic React Prop Passing Example
// <Mother /> is a container component that holds the
// application's state.
// In this case, <Mother /> holds the family's lastName.
class Mother extends React.Component {
state = {
lastName: 'Sanchez'
}
render () {
// Mother passes the lastName down one
// level to the <Child />
<Child lastName={this.state.lastName} />
}
}
// <Child /> is a presentational component that
// displays the lastName.
const Child = ({ lastName }) => <p>{lastName}>/p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment