Skip to content

Instantly share code, notes, and snippets.

@Kellswork
Created September 29, 2021 22:07
Show Gist options
  • Save Kellswork/e6996620175d6d38faa24fcc3109a2d2 to your computer and use it in GitHub Desktop.
Save Kellswork/e6996620175d6d38faa24fcc3109a2d2 to your computer and use it in GitHub Desktop.
Converting JSX Form to a Controlled Form with React Hooks
import { useState } from "react";
export default function UserForm() {
const [contactInfo, setContactInfo] = useState({
name: "",
email: "",
phonenumber: "",
});
return (
<div className="form-container">
<form>
<div>
<h3>Contact Form</h3>
</div>
<div>
<input
type="text"
name="name"
placeholder="Name"
value={contactInfo.name}
/>
</div>
<div>
<input
type="email"
name="email"
placeholder="Email"
value={contactInfo.email}
/>
</div>
<div>
<input
type="number"
name="phonenumber"
placeholder="Phone Number"
value={contactInfo.phonenumber}
/>
</div>
<div>
<button>Submit Contact</button>
</div>
</form>
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment