Skip to content

Instantly share code, notes, and snippets.

@FarhadG
Last active July 22, 2017 23:44
Show Gist options
  • Save FarhadG/bcf0903fe9f1a064d7e24e6d0ed00236 to your computer and use it in GitHub Desktop.
Save FarhadG/bcf0903fe9f1a064d7e24e6d0ed00236 to your computer and use it in GitHub Desktop.
Clever Event Handlers in React
class CustomComponent extends Component {
handleClick = (i, str) => (e) => {
...
};
render() {
return (
<ul>
{data.map((i) => (
{/*
higher order functions in cases where you need to pass index or other custom values over
the traditional inline arrow func: `(e) => this.handleClick(i, 'someCustomValue', e)`
inline binding, custom html attributes, and so forth...
*/}
<li onClick={this.handleClick(i, 'someCustomValue')}>
...
</li>
)}
</ul>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment