Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
22
rated 0 times [  27] [ 5]  / answers: 1 / hits: 29514  / 4 Years ago, wed, january 15, 2020, 12:00:00

I want to use a type for my event handler instead of using type any,
Can anyone help me with this,please?
here is the code I'm trying to refactor:



const MyComponent = () => {
const handleBtnClick = (e: any) => {
e.stopPropagation();
//**Some Code**
}
return <CustomButton onClick={handleBtnClick} />
}

More From » reactjs

 Answers
77

If you create a <button> and hover over onClick prop you'll get the type in the tooltip:



enter



In your example code, you are creating a custom button so the types depend on the implementation of that component.


[#51301] Tuesday, January 7, 2020, 4 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
larrycodys

Total Points: 394
Total Questions: 93
Total Answers: 78

Location: Romania
Member since Mon, Jun 6, 2022
2 Years ago
;