Skip to content

Instantly share code, notes, and snippets.

@i-oliva
Created November 26, 2019 17:45
Show Gist options
  • Save i-oliva/af5d673318dc0e698994bbcaeb12e80e to your computer and use it in GitHub Desktop.
Save i-oliva/af5d673318dc0e698994bbcaeb12e80e to your computer and use it in GitHub Desktop.
import { Formik } from "formik";
import React from "react";
import * as yup from "yup";
type SignInForm = {
email: string;
password: string;
};
type SignInProps = {
onSubmit: ({ email, password }: SignInForm) => void;
Form: React.ElementType;
validationSchema: yup.ObjectSchema<
yup.Shape<
object,
{
email: string;
password: string;
}
>
>;
};
export default ({ onSubmit, Form, validationSchema }: SignInProps) => {
return (
<Formik
initialValues={{ email: "", password: "" }}
validationSchema={validationSchema}
onSubmit={values => {
const { email, password } = values;
onSubmit({ email, password });
}}
>
{({ handleChange, handleBlur, handleSubmit, values }) => {
return (
<Form
handleChange={handleChange}
handleBlur={handleBlur}
handleSubmit={handleSubmit}
values={values}
/>
);
}}
</Formik>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment