Skip to content

Commit 4ff1c5c

Browse files
committed
Revert "Try using forwardRef (bypassed commit hooks, sorry!)"
This reverts commit 67ff970.
1 parent 67ff970 commit 4ff1c5c

File tree

2 files changed

+6
-22
lines changed

2 files changed

+6
-22
lines changed

packages/formik/src/Formik.tsx

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
FieldHelperProps,
1414
FieldInputProps,
1515
FormikHelpers,
16-
FormikContextType,
1716
} from './types';
1817
import {
1918
isFunction,
@@ -29,7 +28,6 @@ import {
2928
import { FormikProvider } from './FormikContext';
3029
import invariant from 'tiny-warning';
3130
import { LowPriority, unstable_runWithPriority } from 'scheduler';
32-
import { FormikBag } from './withFormik';
3331

3432
type FormikMessage<Values> =
3533
| { type: 'SUBMIT_ATTEMPT' }
@@ -996,15 +994,15 @@ export function useFormik<Values extends FormikValues = FormikValues>({
996994
return ctx;
997995
}
998996

999-
export const Formik = React.forwardRef(<
997+
export function Formik<
1000998
Values extends FormikValues = FormikValues,
1001999
ExtraProps = {}
1002-
>(props: FormikConfig<Values> & ExtraProps, ref: React.Ref<FormikContextType<Values>>) => {
1000+
>(props: FormikConfig<Values> & ExtraProps) {
10031001
const formikbag = useFormik<Values>(props);
1004-
const { component, children, render } = props;
1002+
const { component, children, render, innerRef } = props;
10051003

10061004
// This allows folks to pass a ref to <Formik />
1007-
React.useImperativeHandle(ref, () => formikbag);
1005+
React.useImperativeHandle(innerRef, () => formikbag);
10081006

10091007
React.useEffect(() => {
10101008
if (__DEV__) {
@@ -1032,10 +1030,7 @@ export const Formik = React.forwardRef(<
10321030
: null}
10331031
</FormikProvider>
10341032
);
1035-
}) as <
1036-
Values extends FormikValues = FormikValues,
1037-
ExtraProps = {}
1038-
>(props: FormikConfig<Values> & ExtraProps & React.RefAttributes<FormikContextType<Values>>) => JSX.Element;
1033+
}
10391034

10401035
function warnAboutMissingIdentifier({
10411036
htmlContent,

packages/formik/test/Formik.test.tsx

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as React from 'react';
22
import { render, fireEvent, wait } from 'react-testing-library';
3-
import { FormikContextType } from '../src/types';
43
import * as Yup from 'yup';
54

65
import {
@@ -51,7 +50,7 @@ function Form({
5150

5251
const InitialValues = { name: 'jared' };
5352

54-
function renderFormik<V = Values>(props?: Partial<FormikConfig<V>> & React.RefAttributes<FormikContextType<Values>>) {
53+
function renderFormik<V = Values>(props?: Partial<FormikConfig<V>>) {
5554
let injected: any;
5655
const { rerender, ...rest } = render(
5756
<Formik
@@ -1297,14 +1296,4 @@ describe('<Formik>', () => {
12971296

12981297
expect(innerRef.current).toEqual(getProps());
12991298
});
1300-
1301-
it('exposes formikbag with forwardRef', () => {
1302-
const ref = React.createRef<FormikContextType<Values>>();
1303-
1304-
const { getProps } = renderFormik({ ref });
1305-
1306-
ref.current.values.name;
1307-
1308-
expect(ref.current).toEqual(getProps());
1309-
});
13101299
});

0 commit comments

Comments
 (0)