Skip to content

Commit

Permalink
Revert "Revert "Change layout of generics in main Formik class (jared…
Browse files Browse the repository at this point in the history
…palmer#370)""

This reverts commit 6c51b70.
  • Loading branch information
jaredpalmer committed Jan 29, 2018
1 parent 6c51b70 commit 6491acd
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/formik.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ export type FormikProps<Values> = FormikState<Values> &
FormikHandlers &
FormikComputedProps<Values>;

export class Formik<
Props extends FormikConfig<Values> = FormikConfig<Values>,
Values = object
> extends React.Component<Props, FormikState<any>> {
export class Formik<ExtraProps = {}, Values = object> extends React.Component<
FormikConfig<Values> & ExtraProps,
FormikState<any>
> {
static defaultProps = {
validateOnChange: true,
validateOnBlur: true,
Expand Down Expand Up @@ -221,7 +221,7 @@ export class Formik<
? this.state.errors && Object.keys(this.state.errors).length === 0
: this.props.isInitialValid !== false &&
isFunction(this.props.isInitialValid)
? (this.props.isInitialValid as (props: Props) => boolean)(
? (this.props.isInitialValid as (props: this['props']) => boolean)(
this.props
)
: (this.props.isInitialValid as boolean),
Expand All @@ -245,7 +245,7 @@ export class Formik<
};
}

constructor(props: Props) {
constructor(props: FormikConfig<Values> & ExtraProps) {
super(props);
this.state = {
values: props.initialValues || ({} as any),
Expand All @@ -257,7 +257,9 @@ export class Formik<
this.initialValues = props.initialValues || ({} as any);
}

componentWillReceiveProps(nextProps: Props) {
componentWillReceiveProps(
nextProps: Readonly<FormikConfig<Values> & ExtraProps>
) {
// If the initialValues change, reset the form
if (
this.props.enableReinitialize &&
Expand Down Expand Up @@ -579,7 +581,7 @@ export class Formik<
isValid: dirty
? this.state.errors && Object.keys(this.state.errors).length === 0
: isInitialValid !== false && isFunction(isInitialValid)
? (isInitialValid as (props: Props) => boolean)(this.props)
? (isInitialValid as (props: this['props']) => boolean)(this.props)
: (isInitialValid as boolean),
handleBlur: this.handleBlur,
handleChange: this.handleChange,
Expand Down Expand Up @@ -622,15 +624,11 @@ function warnAboutMissingIdentifier({
handlerName: string;
}) {
console.error(
`Warning: \`${
handlerName
}\` has triggered and you forgot to pass an \`id\` or \`name\` attribute to your input:
`Warning: \`${handlerName}\` has triggered and you forgot to pass an \`id\` or \`name\` attribute to your input:
${htmlContent}
Formik cannot determine which value to update. For more info see https://github.com/jaredpalmer/formik#${
documentationAnchorLink
}
Formik cannot determine which value to update. For more info see https://github.com/jaredpalmer/formik#${documentationAnchorLink}
`
);
}
Expand Down

0 comments on commit 6491acd

Please sign in to comment.