Home > Blockchain >  Correct Type for onClick handler with multiple parameters
Correct Type for onClick handler with multiple parameters

Time:08-30

I have my original function

const handleClick: React.MouseEventHandler<HTMLButtonElement> = e => {
  e.stopPropagation();
};

I needed to pass multiple parameters so I changed it to the following

const handleClick: any = (send: boolean) => (e: any) => {
  console.log('send', send);
  e.stopPropagation();
};

What should I replace the first and second any with for typescript?

CodePudding user response:

as kelly pointed out, all I had to do was the following

const handleClick: (send: boolean) => React.MouseEventHandler<HTMLButtonElement> = send => e => {
  console.log('send', send);
  e.stopPropagation();
};

CodePudding user response:

Try below code

const newFun = (event: React.MouseEvent<HTMLElement>,send:boolean) => {
console.log(event.target);
console.log(event.currentTarget);
event.stopPropagation();
}




const handleClick = (event: React.MouseEvent<HTMLElement>) =>  newFun(event,true);
  • Related