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

InputControl: Infer type instead of explicit typing #169

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 20 additions & 19 deletions src/input-control/index.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
import { Input, InputProps } from '@chakra-ui/react';
import { useField, useFormikContext } from 'formik';
import React, { FC, ForwardedRef } from 'react';
import React from 'react';
import { BaseProps, FormControl } from '../form-control';

export type InputControlProps = BaseProps & { inputProps?: InputProps };

export const InputControl: FC<InputControlProps> = React.forwardRef(
(props: InputControlProps, ref: ForwardedRef<HTMLInputElement>) => {
const { name, label, inputProps, ...rest } = props;
const [field] = useField(name);
const { isSubmitting } = useFormikContext();
return (
<FormControl name={name} label={label} {...rest}>
<Input
{...field}
id={name}
isDisabled={isSubmitting}
{...inputProps}
ref={ref}
/>
</FormControl>
);
}
);
export const InputControl = React.forwardRef<
HTMLInputElement,
InputControlProps
>((props, ref) => {
const { name, label, inputProps, ...rest } = props;
const [field] = useField(name);
const { isSubmitting } = useFormikContext();
return (
<FormControl name={name} label={label} {...rest}>
<Input
{...field}
id={name}
isDisabled={isSubmitting}
{...inputProps}
ref={ref}
/>
</FormControl>
);
});

export default InputControl;