Here's how you can do it. And here's the working example JSBin: https://jsbin.com/yixano/2/edit?html,js,output
var ModalParent = React.createClass({
getInitialState: function() {
return {showModal: false};
},
toggleShowModal: function() {
this.setState({showModal: !this.state.showModal});
},
render: function() {
return (
<div>
<button type="button" onClick={this.toggleShowModal.bind(this)}>Toggle Show Modal</button>
{this.state.showModal ?
<Modal onModalClose={this.toggleShowModal.bind(this)}/> :
<div></div>}
<h4>State is: </h4>
<pre>{JSON.stringify(this.state, null, 2)}</pre>
</div>);
}
});
var Modal = React.createClass({
render: function(){
return <div><button type="buton" onClick={this.props.onModalClose}>Close</button></div>
}
});
ReactDOM.render(<ModalParent/>, document.getElementById("app"));
The idea here is to pass in a reference to a function on ModalParent to the Modal so that the state in the parent can be altered based on the actions in the child.
As you can see, the child has a prop called "onModalClose" and it needs a function reference which gets invoked on clicking the close button. And in the parent we bind the corresponding toggleShowModal to this onModalClose property.