Untitled

mail@pastecode.io avatar
unknown
javascript
a year ago
625 B
4
Indexable
Never
import { Formik, Form, Field } from 'formik';

const validate = (value) => {
  let error;
  if (!value) {
    error = 'Required';
  }
  return error;
}

const MyForm = () => (
  <Formik
    initialValues={{ inputValue: '' }}
    onSubmit={(values, { setSubmitting }) => {
      setTimeout(() => {
        alert(JSON.stringify(values, null, 2));
        setSubmitting(false);
      }, 400);
    }}
  >
    {({ isSubmitting }) => (
      <Form>
        <Field name="inputValue" validate={validate} />
        <button type="submit" disabled={isSubmitting}>
          Submit
        </button>
      </Form>
    )}
  </Formik>
);