Created
February 7, 2017 23:38
-
-
Save ha404/0b18f6735856be4421e46cc9f3424927 to your computer and use it in GitHub Desktop.
exploring alternatives to .bind
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
class FooBar { | |
// EXAMPLE 1 | |
handleClick = (event) => { | |
console.log(event.target.dataset.id) | |
} | |
// EXAMPLE 2 | |
// handleClick = (data) => () => { | |
// console.log(data) | |
// } | |
// EXAMPLE 3 | |
// handleClick = (data) => { | |
// console.log(data) | |
// } | |
render () { | |
return [1, 2, 3].map((item) => { | |
return ( | |
<div | |
// EXAMPLE 1 | |
data-id={item} | |
onClick={this.handleClick} | |
// EXAMPLE 2 | |
// onClick={this.handleClick(item)} | |
// EXAMPLE 3 | |
// onClick={this.handleClick.bind(this, item)} | |
// EXAMPLE 4 | |
// onClick={(item) => this.handleClick(item)} | |
/> | |
) | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment