Created
September 29, 2021 22:07
-
-
Save Kellswork/e6996620175d6d38faa24fcc3109a2d2 to your computer and use it in GitHub Desktop.
Converting JSX Form to a Controlled Form with React Hooks
This file contains hidden or 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 { 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