Skip to content

Instantly share code, notes, and snippets.

@maecapozzi
Created August 14, 2018 13:46
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/b701dd053cb34246575b8656c700a7dc to your computer and use it in GitHub Desktop.
Save maecapozzi/b701dd053cb34246575b8656c700a7dc to your computer and use it in GitHub Desktop.
class Grandmother extends React.Component {
state = {
lastName: 'Sanchez'
}
// When this function is called, the
// Grandmother's last name is updated
immigrateTo = (country, newLastName) => {
this.setState({ lastName: newLastName })
}
componentDidMount() {
this.immigrateTo('US', 'Smith')
}
render () {
// Even though the Grandmother's last name
// was Sanchez, once her name is changed,
// the Mother inherits the name "Smith."
<Mother lastName={this.state.lastName} />
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment