Created
March 16, 2021 08:27
-
-
Save ricardodantas/38c9567d2f7c86695a0c9d88cfedcdd4 to your computer and use it in GitHub Desktop.
React: Passing event with parameter onClick
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
// 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