Created
May 10, 2022 03:33
-
-
Save adeleke5140/ca61e48b282169615173a617d94f954e to your computer and use it in GitHub Desktop.
collect data from React Form
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 { useState } from "react"; | |
const SignUp = () => { | |
const [values, setValues] = useState(); | |
const onChange = (event) => { | |
setValues({ | |
...values, | |
[event.target.name]: event.target.value | |
}); | |
}; | |
return ( | |
<div> | |
<h1>SignUp</h1> | |
<form | |
onSubmit={(event) => { | |
event.preventDefault(); | |
console.log(values); | |
}} | |
> | |
<label htmlFor="username">Username:</label> | |
<input | |
required | |
type="text" | |
name="username" | |
placeholder="username" | |
onChange={onChange} | |
/> | |
<label htmlFor="email">Username:</label> | |
<input | |
required | |
type="text" | |
name="email" | |
placeholder="email" | |
onChange={onChange} | |
/> | |
<button type="submit">Submit</button> | |
</form> | |
</div> | |
); | |
}; | |
export default function App() { | |
return ( | |
<div className="App"> | |
<SignUp /> | |
</div> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment