Last active
October 23, 2015 22:41
-
-
Save xfsnowind/9202655ffbe7eb39bfeb to your computer and use it in GitHub Desktop.
communication from child to parent and triggered by parent on blog "React -- Communication between components" on 2014/06/24
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
| // For Parent.js | |
| var Parent = React.createClass({ | |
| getInitialState: function () { | |
| return { childRef: "childRef" }; | |
| }, | |
| changeHandler: function () { | |
| // use ref to call the instance of Child | |
| this.refs[this.state.childRef].getChildValue(); | |
| }, | |
| render: function () { | |
| return ( | |
| <div><input onchange="{this.changeHandler}/" type="text" value="Parent"></input><child ref="{this.state.childRef}/"></child></div> | |
| ); | |
| } | |
| }); | |
| // For Child.js | |
| var Child = React.createClass({ | |
| getChildValue: function () { | |
| // here return the value in Child to Parent | |
| }, | |
| render: function () { | |
| return ( | |
| <div. onclick="{this.chickHandler}/" type="button" value="Child"> | |
| ); | |
| } | |
| }); | |
| </div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment