I started play with React and I'm stuck with this sample.
Counter works but why onClick the BUTTON does not change key active in state and render correct button?
Link to CodePen
const Button = ({label}) => (
<button className="btn btn-primary">{label}</button>
);
const Counter = React.createClass({
getInitialState: function () {
return {
counter: 0,
active: false
}
},
increment: function () {
this.setState({
counter: this.state.counter + 1
})
},
change: function () {
this.setState({
active: true
})
},
render: function () {
return (
<div>
<h1>Counter: {this.state.counter}</h1>
<button onClick={this.increment}>1+</button>}
{this.state.active ?
<Button label="Sign OUT"/> :
<Button label="Sign in" onClick={this.change}/>}
</div>
)
}
});
ReactDOM.render(<Counter/>, document.getElementById("root"))