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
Post a Comment