Skip to content

Commit

Permalink
Revert "Try using forwardRef (bypassed commit hooks, sorry!)"
Browse files Browse the repository at this point in the history
This reverts commit 67ff970.
  • Loading branch information
johnrom committed Jan 17, 2020
1 parent 67ff970 commit 4ff1c5c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 22 deletions.
15 changes: 5 additions & 10 deletions packages/formik/src/Formik.tsx
Expand Up @@ -13,7 +13,6 @@ import {
FieldHelperProps,
FieldInputProps,
FormikHelpers,
FormikContextType,
} from './types';
import {
isFunction,
Expand All @@ -29,7 +28,6 @@ import {
import { FormikProvider } from './FormikContext';
import invariant from 'tiny-warning';
import { LowPriority, unstable_runWithPriority } from 'scheduler';
import { FormikBag } from './withFormik';

type FormikMessage<Values> =
| { type: 'SUBMIT_ATTEMPT' }
Expand Down Expand Up @@ -996,15 +994,15 @@ export function useFormik<Values extends FormikValues = FormikValues>({
return ctx;
}

export const Formik = React.forwardRef(<
export function Formik<
Values extends FormikValues = FormikValues,
ExtraProps = {}
>(props: FormikConfig<Values> & ExtraProps, ref: React.Ref<FormikContextType<Values>>) => {
>(props: FormikConfig<Values> & ExtraProps) {
const formikbag = useFormik<Values>(props);
const { component, children, render } = props;
const { component, children, render, innerRef } = props;

// This allows folks to pass a ref to <Formik />
React.useImperativeHandle(ref, () => formikbag);
React.useImperativeHandle(innerRef, () => formikbag);

React.useEffect(() => {
if (__DEV__) {
Expand Down Expand Up @@ -1032,10 +1030,7 @@ export const Formik = React.forwardRef(<
: null}
</FormikProvider>
);
}) as <
Values extends FormikValues = FormikValues,
ExtraProps = {}
>(props: FormikConfig<Values> & ExtraProps & React.RefAttributes<FormikContextType<Values>>) => JSX.Element;
}

function warnAboutMissingIdentifier({
htmlContent,
Expand Down
13 changes: 1 addition & 12 deletions packages/formik/test/Formik.test.tsx
@@ -1,6 +1,5 @@
import * as React from 'react';
import { render, fireEvent, wait } from 'react-testing-library';
import { FormikContextType } from '../src/types';
import * as Yup from 'yup';

import {
Expand Down Expand Up @@ -51,7 +50,7 @@ function Form({

const InitialValues = { name: 'jared' };

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

expect(innerRef.current).toEqual(getProps());
});

it('exposes formikbag with forwardRef', () => {
const ref = React.createRef<FormikContextType<Values>>();

const { getProps } = renderFormik({ ref });

ref.current.values.name;

expect(ref.current).toEqual(getProps());
});
});

1 comment on commit 4ff1c5c

@vercel
Copy link

@vercel vercel bot commented on 4ff1c5c Jan 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.