Skip to content

Instantly share code, notes, and snippets.

@BoDonkey
Created September 29, 2018 13:42
Show Gist options
  • Save BoDonkey/cae15fdc0c01d8293f8371962c290e44 to your computer and use it in GitHub Desktop.
Save BoDonkey/cae15fdc0c01d8293f8371962c290e44 to your computer and use it in GitHub Desktop.
jsx for detecting change in checkbox
/ 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