Last active
August 14, 2018 13:41
-
-
Save maecapozzi/a7b44016cf440ce688f15084846fcbf9 to your computer and use it in GitHub Desktop.
Basic React Prop Passing 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
// <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