mizner
12/10/2016 - 9:43 AM

React State Example

React State Example

var Checkbox = React.createClass({
    getInitialState(){
        return {checked: false}
    },
    handleCheck(){
        this.setState({checked: !this.state.checked})
    },
    render() {
        var msg;
        if (this.state.checked) {
            msg = "checked"
        }
        else {
            msg = "unchecked"
        }
        return (
                <div>
                    <input type="checkbox" onChange={this.handleCheck}/>
                    <p>This box is {msg}</p>
                </div>
        )
    }
})

ReactDOM.render(<Checkbox/>, document.getElementById('react-container'))