简体   繁体   English

FieldRenderProps 与 React Native TextInput

[英]FieldRenderProps with React Native TextInput

I created custom TextInput for final-form in React-Native. And I need to specify type for FieldRenderProps.我在 React-Native 中为最终形式创建了自定义 TextInput。我需要为 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:所以我的 CustomInput 代码:

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?你能帮忙吗,我需要 FieldRenderProps 中的什么类型?

The first parameter of generic FieldRenderProps is FieldValue .通用FieldRenderProps的第一个参数是FieldValue When FieldRenderProps is used with one or two parameters, InputValue is defaulted to FieldValue .FieldRenderProps与一个或两个参数一起使用时, InputValue默认为FieldValue Afaik, InputValue for TextInput should be string. Afaik, TextInputInputValue应该是字符串。 So the type definition for AuthInput can be FC<FieldRenderProps<string>>所以 AuthInput 的类型定义可以是FC<FieldRenderProps<string>>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM