Skip to content

Instantly share code, notes, and snippets.

@ricardodantas
Created March 16, 2021 08:27
Show Gist options
  • Save ricardodantas/38c9567d2f7c86695a0c9d88cfedcdd4 to your computer and use it in GitHub Desktop.
Save ricardodantas/38c9567d2f7c86695a0c9d88cfedcdd4 to your computer and use it in GitHub Desktop.
React: Passing event with parameter onClick
// ES6
const clickHandler = (parameter) => (event) => {
// Do something
alert('Here is your parameter:', parameter);
};
// -----
// Standard JS
"use strict";
var clickHandler = function clickHandler(parameter) {
return function (event) {
// Do something
};
};
//-----
// Use it:
<button onClick={clickHandler(someParameter)} />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment