Skip to content

Instantly share code, notes, and snippets.

@adeleke5140
Created May 10, 2022 03:33
Show Gist options
  • Save adeleke5140/ca61e48b282169615173a617d94f954e to your computer and use it in GitHub Desktop.
Save adeleke5140/ca61e48b282169615173a617d94f954e to your computer and use it in GitHub Desktop.
collect data from React Form
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