Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hemepositive/dec0dd1b45396ca507a3fd4a13326b81 to your computer and use it in GitHub Desktop.
Save hemepositive/dec0dd1b45396ca507a3fd4a13326b81 to your computer and use it in GitHub Desktop.
React event handler with parameters using property initializer syntax CURRYING
// 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