Created
October 16, 2019 09:58
-
-
Save marcuszierke/c3b7b09320951c24a15be0c35f9da718 to your computer and use it in GitHub Desktop.
React Contact Form without using state
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
import React from 'react'; | |
const ContactForm = () => { | |
function handleSubmit(event) { | |
event.preventDefault(); | |
const data = {}; | |
const formElements = Array.from(event.target); | |
formElements.map(input => (data[input.name] = input.value)); | |
} | |
return ( | |
<div> | |
<form onSubmit={handleSubmit}> | |
<input name="firstName" type="text">First Name<input> | |
<input name="lastName" type="text">Last Name<input> | |
<input name="address" type="text">Adress<input> | |
<input name="zip" type="text">Zipcode<input> | |
<input name="city" type="text">City<input> | |
... | |
<button type="submit">Submit</button> | |
</form> | |
</div> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment