Created
April 26, 2021 10:21
-
-
Save weslleyaraujo/a72da842075f7608be5bddc1e9ec443d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Define which elements this form is going to have | |
interface FormElements extends HTMLFormControlsCollection { | |
fieldName: HTMLInputElement; | |
} | |
// Set a "HTMLFormElement" interface with those elements | |
interface MyForm extends HTMLFormElement { | |
readonly elements: FormElements; | |
} | |
function Foo() { | |
return ( | |
<form onSubmit={(event: React.SyntheticEvent<MyForm>) => { | |
// form elements are going to be defined under: | |
event.currentTarget.elements; | |
// get value of a field | |
event.currentTarget.elements.fieldName.value; | |
}}> | |
{/* ... */} | |
</form> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment