Skip to content

Instantly share code, notes, and snippets.

@joaocarvalhowd
Created April 9, 2019 13:35
Show Gist options
  • Save joaocarvalhowd/a97e64820bb71fe0b527c46b7b51549d to your computer and use it in GitHub Desktop.
Save joaocarvalhowd/a97e64820bb71fe0b527c46b7b51549d to your computer and use it in GitHub Desktop.
Get value
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 = {
name: fields.name.current.value,
github: fields.github.current.value,
linkedin: fields.linkedin.current.value,
website: fields.website.current.value
};
};
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