Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update FieldProps to mimic formik handlers #1287

Merged
merged 1 commit into from Feb 6, 2019
Merged

Update FieldProps to mimic formik handlers #1287

merged 1 commit into from Feb 6, 2019

Conversation

lukaskral
Copy link
Contributor

This change fixes the type signature for the onChange handler, which can be called with a string as a 1st argument.

Example code:

import * as React from 'react';
import {Field, FieldProps} from 'formik';

import {TextAreaField} from 'my-own-ui';

interface IProps {
    id: string;
    label: string;
}

function TextArea({id, label}: IProps) {
    return (
        <Field
            name={id}
            render={({field}: FieldProps) => {
                return (
                      <TextAreaField
                          label={component.label || ''}
                          value={field.value}
                          onChange={(val: string) => field.onChange(val)}
                      />
                );
            }}
        />
    );
}

Up until now this wasn't possible in Typescript because field.onChange only accepts React.ChangeEvent<any>

This change fixes the type signature for the onChange handler, which can be called with a string as a 1st argument.
@jaredpalmer
Copy link
Owner

LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants