Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yuriitaran/1348eb47b8bc8d2730c2c100000275eb to your computer and use it in GitHub Desktop.
Save yuriitaran/1348eb47b8bc8d2730c2c100000275eb to your computer and use it in GitHub Desktop.
Binding of 'this'
class Checkbox extends React.Component {
constructor() {
super();
this.state = {
checked: false
};
this.handleClick = this.handleClick.bind(this);
}
handleClick(e) {
this.setState({ checked: !this.state.checked });
}
render() {
return(
<button className="icon checkbox" onClick={this.handleClick}>
<i className="material-icons">
{this.state.checked ? 'check_box' : 'check_box_outline_blank'}
</i>
</button>
);
}
};
class Checkbox extends React.Component {
constructor() {
super();
this.state = {
checked: false
};
}
handleClick(e) {
this.setState({ checked: !this.state.checked });
}
render() {
return(
<button className="icon checkbox" onClick={this.handleClick.bind(this)}>
<i className="material-icons">
{this.state.checked ? 'check_box' : 'check_box_outline_blank'}
</i>
</button>
);
}
};
class Checkbox extends React.Component {
constructor() {
super();
this.state = {
checked: false
};
}
handleClick = (e) => {
this.setState({ checked: !this.state.checked });
}
render() {
return(
<button className="icon checkbox" onClick={this.handleClick}>
<i className="material-icons">
{this.state.checked ? 'check_box' : 'check_box_outline_blank'}
</i>
</button>
);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment