首页 > 解决方案 > 输入符号后,redux-form 的 React-native Input HOC 失去焦点

问题描述

我正在尝试使用 redux-form,但是,当我阅读时,我需要 HOC 用于输入字段以将 onTextChange 替换为 onChange。我有:

import React from 'react';
import {Input} from 'native-base';

export default function InputField(props) {
    const { input, ...inputProps } = props;

    return (
        <Input
            {...inputProps}
            onChangeText={input.onChange}
            onBlur={input.onBlur}
            onFocus={input.onFocus}
            value={input.value}
        />
    );
};

并以我的形式使用它:

<Item style={{marginTop: 10, width: "100%"}}>
    <Field name="login" component={(props) => {
        return (
            <InputField {...props} keyboardType="email-address" placeholder='E-mail' />
        )
    }}/>
</Item>

但是每次我键入键时,该字段都会失去焦点。一些“专家”建议使用 focus() 函数。但是,如果我在其中编辑文本怎么办?有什么解决办法吗?或者也许原生基础具有兼容的文本字段组件?

标签: react-nativeredux-formnative-base

解决方案


It is strange, but it works ))

function InputFieldEmail(props) {
    return <InputField {...props} keyboardType="email-address" placeholder='E-mail' />;
}

and use it instead arrow functions

<Field name="login" component={InputFieldEmail}/>

I think it's strange )


推荐阅读