-
-
Save FarhadG/bcf0903fe9f1a064d7e24e6d0ed00236 to your computer and use it in GitHub Desktop.
Clever Event Handlers in React
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 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