我在React Native中为最终表单创建了自定义TextInput。我需要指定FieldRenderProps的类型。我有一个错误:
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>'.
所以我的自定义输入代码:
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;
你能帮我吗,我在FieldRenderDrops中需要什么类型的?
泛型FieldRenderProps
的第一个参数是FieldValue
。当FieldRenderProps
与一个或两个参数一起使用时,InputValue
默认为FieldValue
。Afaik,TextInput
的InputValue
应该是字符串。因此AuthInput的类型定义可以是FC<FieldRenderProps<string>>