Formik: [V2] useFormikContext doesn't return valitationSchema as expected

Created on 6 Dec 2019  路  3Comments  路  Source: formium/formik

馃悰 Bug report

The documentation says that the returned value from useFormikContext is the same as the formik props of connect, that includes validationSchema. Also the type definition asserts that useFormikContext return value includes validationSchema, but in effect it currently doesn`t.

Current Behavior

useFormikContext return value does`t includs validationSchema

Reproducible example

Iinclude the following test in the source code
````
import * as React from 'react';
import { render } from 'react-testing-library';
import { Formik } from '../src/Formik';
import { useFormikContext } from '../src/FormikContext';

describe('FormikContext', () => {
describe('useFormikContext', () => {
it('should return validationContext if set', () => {
const validationSchema = 'validationSchema';

  const AComponenent: React.FC = () => {
    const formikContext = useFormikContext();
    expect(formikContext.validationSchema).toBe(validationSchema);
    return null;
  };

  render(
    <Formik
      initialValues={{ test: '' }}
      validationSchema={validationSchema}
      onSubmit={() => {}}
    >
      <AComponenent />
    </Formik>
  );
});

});
});
````
The test fails

Expected behavior

The test should pass.

Suggested solution(s)

PR https://github.com/jaredpalmer/formik/pull/2090 fixes the issue

Your environment

| Software | Version(s) |
| ---------------- | ---------- |
| Formik | 2.06
| React | 16,9,2
| TypeScript | 3.7.2
| Browser | Firefox
| Operating System | Windows 10

stale

Most helpful comment

+1 Same is for connect() - not returning validationSchema too! It was important for me to mark required fields with hint, depending on schema - now i can't find any way to get it!

All 3 comments

+1 Same is for connect() - not returning validationSchema too! It was important for me to mark required fields with hint, depending on schema - now i can't find any way to get it!

+1 for connect() too, to put asterik on required fields

@jaredpalmer it appears as though resolving this would give back a very simple workaround for https://github.com/formium/formik/issues/1241 and https://github.com/formium/formik/issues/712

Would you accept a PR on this, or is it all hands on v3 for now?

Was this page helpful?
0 / 5 - 0 ratings