Reputation: 5531
I have a button as below
<a href="#" className={classes.btnText} onClick={showDetail}>Learn more <span> → </span> </a>
and able to get the event object
const showDetail = event => {
console.log("show detail",event);
}
Now i want to pass an argument on button click. can some one please tell me how to pass event plus an parameter on button click like showDetail(event, "test")
and i dont want the function to be invoked until the button is clicked
Upvotes: 0
Views: 143
Reputation: 402
<a href="#" className={classes.btnText} onClick={(e) => showDetail(e, "test")}>Learn more <span> → </span> </a>
const showDetail = (event, additionalData) => {
console.log("show detail", additionalData, event);
}
Upvotes: 4
Reputation: 4528
const showDetail = type => event => {
console.log("show detail", type, event);
}
<a href="#" className={classes.btnText} onClick={showDetail("test")}>
Learn more <span> → </span>
</a>
this is a currying function, the type
variable can be accessed from event callback
Upvotes: 1