Created
September 29, 2018 13:42
-
-
Save BoDonkey/cae15fdc0c01d8293f8371962c290e44 to your computer and use it in GitHub Desktop.
jsx for detecting change in checkbox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/ External Dependencies | |
import React, { Component } from 'react'; | |
// Internal Dependencies | |
import './style.css'; | |
class HelloWorld extends Component { | |
static slug = 'adna_hello_world'; | |
constructor(props) { | |
super(props); | |
this.checkedRef = React.createRef(); | |
this.state = {isChecked: false}; | |
this.handleChecked = this.handleChecked.bind(this); | |
} | |
handleChecked() { | |
this.setState({ isChecked: !this.state.isChecked }); | |
console.log(this.state.isChecked); | |
} | |
componentDidUpdate() { | |
console.log('Box was checked'); | |
} | |
render() { | |
return ( | |
<div> | |
<label className="switch"> | |
<input ref={this.checkRef} type="checkbox" onChange={this.handleChecked} /> | |
<span className="slider"></span> | |
</label> | |
</div> | |
); | |
} | |
} | |
export default HelloWorld; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment