Skip to content

Instantly share code, notes, and snippets.

@kocisov
Created May 1, 2017 17:03
Show Gist options
  • Save kocisov/a52728704903b64e70bf6d2636c97002 to your computer and use it in GitHub Desktop.
Save kocisov/a52728704903b64e70bf6d2636c97002 to your computer and use it in GitHub Desktop.
class FirstComponent extends Component {
state = {
a: 2
}
changeState = val => {
this.setState({
a: val
})
}
render() {
return (
<div>
<SecondComponent function={this.changeState} />
</div>
)
}
}
// onClick it will change state of first component
class SecondComponent extends Component {
render() {
return (
<div>
<button onClick={() => {
this.props.function(3)
}} />
</div>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment