Forked from sanketmeghani/event-handlers-with-parameters-property-initializer.js
Last active
June 11, 2018 18:35
-
-
Save hemepositive/dec0dd1b45396ca507a3fd4a13326b81 to your computer and use it in GitHub Desktop.
React event handler with parameters using property initializer syntax CURRYING
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
// To pass parameters to event handlers while using property initializer syntax, we need to use currying. | |
// https://medium.freecodecamp.org/reactjs-pass-parameters-to-event-handlers | |
// Currying is the process of taking a function with multiple arguments and | |
// turning it into a sequence of functions each with only a single argument. | |
//https://medium.com/front-end-hacking/javascript-es6-curry-functions-with-practical-examples | |
handleClick = (param) => (e) => { | |
console.log('Event', e); | |
console.log('Parameter', param); | |
} | |
render() { | |
<button onClick={this.handleClick('Parameter')}></button> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment