Last active
January 12, 2017 13:12
-
-
Save HugoDF/cb0c027acbb5ddc6159f650fe9149945 to your computer and use it in GitHub Desktop.
Example of partial application in JavaScript applied to React Component event handlers
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 MyComponent extends React.Component { | |
partialHandleLinkClick(type, activeType){ | |
return function(e) { | |
const hasKeyboardModifier = e.ctrlKey || e.shiftKey || e.altKey || e.metaKey; | |
updateType(type, activeType, hasKeyboardModifier); | |
}; | |
} | |
render() { | |
const types = [ 'Foo', 'Bar', 'Baz' ]; | |
return ( | |
<div> | |
{ | |
types.map( (type, i) => { | |
<a key={i} href="#" | |
onClick={this.partialHandleLinkClick(type, this.props.activeType)}> | |
{type} | |
</a> | |
}) | |
} | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment