I have a simple component
that maintains an internal state. I have another component
that toggles whether or not <
I'm not an expert in React but particularly your case could be solved very cleanly without any mutable objects.
var StatefulView = React.createClass({
getInitialState: function() {
return {
count: 0
}
},
inc: function() {
this.setState({count: this.state.count+1})
},
render: function() {
return !this.props.show ? null : (
count:{this.state.count}
)
}
});
var App = React.createClass({
getInitialState: function() {
return {
show: true,
component: StatefulView
}
},
toggle: function() {
this.setState({show: !this.state.show})
},
render: function() {
return (
)
}
});
ReactDOM.render(
,
document.getElementById('container')
);
You can see it at jsfiddle.