Created
April 26, 2017 17:42
-
-
Save danethurber/446f110985875d0e8479faed52f3d99b to your computer and use it in GitHub Desktop.
React Binding
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 TestComponent extends Component() { | |
handleClick(evt) { | |
console.log(evt) | |
} | |
render() { | |
return <button onClick={e => this.handleClick(e)}>Click Me</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
import { autobind } from 'core-decorators' | |
@autobind | |
class TestComponent extends Component() { | |
handleClick() { | |
console.log(evt) | |
} | |
render() { | |
return <button onClick={this.handleClick}>Click Me</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 TestComponent extends Component() { | |
handleClick(evt) { | |
console.log(evt) | |
} | |
render() { | |
return <button onClick={this.handleClick.bind(this)}>Click Me</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 TestComponent extends Component() { | |
handleClick = (evt) => { | |
console.log(evt) | |
} | |
render() { | |
return <button onClick={this.handleClick}>Click Me</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 TestComponent extends Component() { | |
constructor(props) { | |
super(props) | |
this.handleClick = ::this.handleClick | |
} | |
handleClick(evt) { | |
console.log(evt) | |
} | |
render() { | |
return <button onClick={this.handleClick}>Click Me</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 TestComponent extends Component() { | |
constructor(props) { | |
super(props) | |
this.handleClick = this.handleClick.bind(this) | |
} | |
handleClick(evt) { | |
console.log(evt) | |
} | |
render() { | |
return <button onClick={this.handleClick}>Click Me</button> | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment