Created
April 9, 2019 13:40
-
-
Save joaocarvalhowd/86fa6840b7e6115b072a0c36ac106763 to your computer and use it in GitHub Desktop.
More easily
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 React, { useRef } from "react"; | |
import { | |
AppBar, Typography, Toolbar, TextField | |
} from "@material-ui/core"; | |
function App() { | |
const fields = { | |
name: useRef(), | |
github: useRef(), | |
linkedin: useRef(), | |
website: useRef() | |
}; | |
const handleSubmit = e => { | |
e.preventDefault(); | |
const data = Object.keys(fields).reduce( | |
(acc, field) => ({ ...acc, [field]: field[field].current.value }), | |
{} | |
); | |
console.log(data); | |
}; | |
return ( | |
<> | |
<AppBar position="static" color="default"> | |
<Toolbar> | |
<Typography variant="h6" color="inherit"> | |
Performance Form | |
</Typography> | |
</Toolbar> | |
</AppBar> | |
<form onSubmit={handleSubmit}> | |
<TextField | |
ref={fields.name} | |
label="Name:" | |
fullWidth | |
/> | |
<TextField | |
ref={fields.github} | |
label="Github:" | |
fullWidth | |
/> | |
<TextField | |
ref={fields.linkedin} | |
label="Linkedin:" | |
fullWidth | |
/> | |
<TextField | |
ref={fields.website} | |
label="Website:" | |
fullWidth | |
/> | |
</form> | |
</> | |
); | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment