Skip to content

Instantly share code, notes, and snippets.

@joaocarvalhowd
Last active April 9, 2019 13:27
Show Gist options
  • Save joaocarvalhowd/2d76ff4f9e47547ccde7656df065b29b to your computer and use it in GitHub Desktop.
Save joaocarvalhowd/2d76ff4f9e47547ccde7656df065b29b to your computer and use it in GitHub Desktop.
React - example form with useRef
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()
};
return (
<>
<AppBar position="static" color="default">
<Toolbar>
<Typography variant="h6" color="inherit">
Performance Form
</Typography>
</Toolbar>
</AppBar>
<form>
<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