Skip to content

Instantly share code, notes, and snippets.

@mfrancois3k
Forked from phucdph/MaterialUIForm.tsx
Created June 2, 2022 18:36
Show Gist options
  • Save mfrancois3k/b9480698ce844d9e933de4eb4396dc53 to your computer and use it in GitHub Desktop.
Save mfrancois3k/b9480698ce844d9e933de4eb4396dc53 to your computer and use it in GitHub Desktop.
[Formik] Material UI Form
const MaterialForm = () => {
const handleSubmit = React.useCallback((values: IFormValues, actions) => {
signUp(values);
actions.setSubmitting(false);
}, []);
return (
<Formik<IFormValues>
initialValues={{
username: "",
name: "",
email: "",
password: "",
password_confirmation: ""
}}
onSubmit={handleSubmit}
validationSchema={validationSchema}
>
{({ isSubmitting }) => (
<Form>
<FastField
type="name"
name="name"
label="Name"
disabled={isSubmitting}
component={TextField}
/>
<FastField
type="email"
name="email"
label="Email"
disabled={isSubmitting}
component={TextField}
/>
<FastField
type="text"
name="username"
label="Username"
disabled={isSubmitting}
component={TextField}
/>
<FastField
type="password"
name="password"
label="Password"
disabled={isSubmitting}
component={TextField}
/>
<FastField
type="password"
name="password_confirmation"
label="Retype Password"
disabled={isSubmitting}
component={TextField}
/>
<br />
<Button type="submit" disabled={isSubmitting} color="primary">
Submit
</Button>
<Button type="reset" disabled={isSubmitting}>
Reset
</Button>
</Form>
)}
</Formik>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment