coforma/swift-tech-challenge

View on GitHub
src/app/components/form/USWDSForm.tsx

Summary

Maintainability
A
0 mins
Test Coverage
B
88%
"use client";

import { Form, Formik } from "formik";
import * as yup from "yup";

export const USWDSForm = ({
  initialValues,
  validationSchema,
  submit,
  children,
}: Props) => {
  return (
    <Formik
      initialValues={initialValues}
      validationSchema={validationSchema}
      onSubmit={(values, { setSubmitting }) => {
        setSubmitting(true);
        submit(values);
        setSubmitting(false);
      }}
    >
      {() => {
        return <Form>{children}</Form>;
      }}
    </Formik>
  );
};

type Props = {
  initialValues: { [key: string]: any };
  validationSchema?: yup.ObjectSchema<any>;
  submit: Function;
  children: any;
};