Skip to content

Instantly share code, notes, and snippets.

@weslleyaraujo
Created April 26, 2021 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weslleyaraujo/a72da842075f7608be5bddc1e9ec443d to your computer and use it in GitHub Desktop.
Save weslleyaraujo/a72da842075f7608be5bddc1e9ec443d to your computer and use it in GitHub Desktop.
// 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