Created
May 1, 2017 17:03
-
-
Save kocisov/a52728704903b64e70bf6d2636c97002 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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