Skip to content

Instantly share code, notes, and snippets.

@ha404

ha404/no-bind.js

Created Feb 7, 2017
Embed
What would you like to do?
exploring alternatives to .bind
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