Skip to content

Instantly share code, notes, and snippets.

@xfsnowind
Created October 23, 2015 22:42

Revisions

  1. xfsnowind created this gist Oct 23, 2015.
    33 changes: 33 additions & 0 deletions child->parent-trigged-child.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    // For Parent.js
    var Parent = React.createClass({
    getInitialState: function () {
    return { parentValue: "" };
    },

    // the callback function is passed to Child as props
    passValueFunc: function (para) {
    // handle the passed value from Child
    },

    render: function () {
    return (
    <div><input type="text" value="Parent"></input>
    // pass passValueFunc method as props to Child
    <child getparentvalue="{this.passValueFunc}"></child></div>
    );
    }
    });

    // For Child.js
    var Child = React.createClass({
    clickHandler: function () {
    // pass parameter to Parent's method
    this.props.getParentValue("parentValue");
    },

    render: function () {
    return (
    <div><input onclick="{this.clickHandler}/" type="button" value="Child"></input></div>
    );
    }
    });