import type { ComponentProps, Ref } from 'react'; import { Controller, get, useFormContext } from 'react-hook-form'; import { KeyboardTypeOptions, TextInput } from 'react-native'; import { TextField } from '../form/TextField'; type FormTextFieldProps = Omit, 'ref'> & { // This has to be done to avoid annoying type conflicts with `vue`. inputRef?: Ref; name: string; readOnly?: boolean; keyboardType?: KeyboardTypeOptions; }; export function FormTextField({ name, keyboardType, readOnly, inputRef, ...restOfProps }: FormTextFieldProps) { const form = useFormContext(); const errors = form?.formState?.errors || ''; const errorMessage = errors && get(errors, name)?.message; return ( ( onChange(value.length === 1 ? value.trim() : value)} value={value} editable={!readOnly} {...restOfProps} /> )} name={name} /> ); }