reactjs - Sending event handlers as props into a React component using TypeScript -


i have following code react component. what's right way declare 2 onclick handlers passed component?

interface loginformprops {     loginclicked: ???? <--- onclick handler signature     cancelclicked: ???? <--- onclick handler signature }  class loginform extends react.component<loginformprops, {}> {     render() {         <form>             <button onclick={loginclicked}>                 login             </button>             <button onclick={cancelclicked}>                 cancel             </button>         </form>     } } 

i typically use:

interface iloginformprops {     loginclicked: (ev) => void;     // } 

but if want strict typing:

interface iloginformprops {     loginclicked: (ev: react.mouseevent<htmlbuttonelement>) => void;     // } 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -