React: Need to call parent to re-render component

You might also pass down a function from the parent component to the child component via the props of the child component, then upon an action of function being executed in the child component, you could simply call the function that was passed in.

For instance:

var ParentComponent = React.createClass({
    update: function() {
        this.setState({somethingToUpdate: "newValue"});
        console.log("updated!");
    },
    render: function() {
      <ChildComponent callBack={this.update} />
    }
})

var ChildComponent = React.createClass({
    render: function() {
      <button onClick={this.props.callBack}>click to update parent</button>
    }
})

Tags:

Reactjs