Created
August 30, 2018 23:43
-
-
Save yuriitaran/1348eb47b8bc8d2730c2c100000275eb to your computer and use it in GitHub Desktop.
Binding of 'this'
This file contains hidden or 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
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> | |
); | |
} | |
}; |
This file contains hidden or 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
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> | |
); | |
} | |
}; |
This file contains hidden or 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
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