Skip to content

Instantly share code, notes, and snippets.

@marcuszierke
Created October 16, 2019 09:58
Show Gist options
  • Save marcuszierke/c3b7b09320951c24a15be0c35f9da718 to your computer and use it in GitHub Desktop.
Save marcuszierke/c3b7b09320951c24a15be0c35f9da718 to your computer and use it in GitHub Desktop.
React Contact Form without using state
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