Skip to content

Instantly share code, notes, and snippets.

@xfsnowind
Last active October 23, 2015 22:41
Show Gist options
  • Select an option

  • Save xfsnowind/9202655ffbe7eb39bfeb to your computer and use it in GitHub Desktop.

Select an option

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
// 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