If I understand your question correctly, you are trying to update which component to display when the state changes (e.g. the user creates an account), with that state being altered by a child component. Here is a basic example showing child -> parent communication.
In this case, the RegisterAccount
component is a root component. If it was a child of another component(s) which also needed to know the hasAccount
state used in this example, then the state would likely be better off stored higher up the chain (and passed down as a prop).
jsfiddle of this example
/** @jsx React.DOM */
var AddAccount = React.createClass({
handleRegistration: function() {
this.props.updateAccount(true);
},
render: function() {
return <a onClick={this.handleRegistration}>Create my account</a>;
}
});
var AccountAdded = React.createClass({
render: function() {
return <span>Account exists now</span>;
}
});
var RegisterAccount = React.createClass({
getInitialState: function() {
return {
hasAccount: false
};
},
updateAccountStatus: function(status) {
this.setState({
hasAccount: status
});
},
render: function() {
return (
<div>
{this.state.hasAccount ? <AccountAdded /> : <AddAccount updateAccount={this.updateAccountStatus} />}
</div>
);
}
});
React.renderComponent(<RegisterAccount />, document.body);