'FieldRenderProps with React Native TextInput
I created custom TextInput for final-form in React-Native. And I need to specify type for FieldRenderProps. And I have an error:
TS2769: No overload matches this call. Overload 1 of 2, '(props: TextInputProps | Readonly<TextInputProps>): TextInput',
gave the following error.
Type '{ name: string; onBlur:
(event?: FocusEvent<HTMLElement, Element> | undefined) => void;
onChange: (event: any) => void; onFocus: (event?: FocusEvent<HTMLElement, Element> | undefined) => void; type?: string | undefined; value: TextInputProps;
checked?: boolean | undefined; multiple?: boolean | undefined; }' is not assignable to type 'Readonly<TextInputProps>'.
So my CustomInput code:
import React, {FC} from 'react';
import {FieldRenderProps} from 'react-final-form';
import {TextInput, TextInputProps} from 'react-native';
const AuthInput: FC<FieldRenderProps<TextInputProps>> = ({input}) => {
return <TextInput {...input} />;
};
export default AuthInput;
Can you help, what type I need in FieldRenderProps?
Solution 1:[1]
The first parameter of generic FieldRenderProps is FieldValue. When FieldRenderProps is used with one or two parameters, InputValue is defaulted to FieldValue. Afaik, InputValue for TextInput should be string. So the type definition for AuthInput can be FC<FieldRenderProps<string>>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Evgeny Timoshenko |
