I would like to wrap the functions, which will be called on the onClick Event, into another function, which executes some additional actions before the passed function will be executed. Therefore I would like have a function which accepts a function as prop with an optional parameter.
Something like:
import React from "react";
import action from ...
export default class C extends React.Component {
constructor(props) {
super(props);
}
handleClickLinkOne(shift) {
// do Stuff
}
handleClickLinkTwo(){
// do Stuff
}
render() {
return (
<React.Fragment>
<a
className={...}
onClick={(e) => action(this.handleClickLinkOne(e.shiftKey))}
>
CAPTION
</a>
<a
className={...}
onClick={() => action(this.handleClickLinkTwo())}
>
CAPTION TWO
</a>
<React.Fragment>
);
}
}
function action(prop){
// do stuff
prop();
}
My problem is that I don't know exactly how to handle the optional "e" parameter.