0
votes

I'm trying to use redux-form, but, as I read, I need HOC for Input field to replace onTextChange to onChange. I have:

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}
        />
    );
};

and use it in my form:

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

But every time I type key, the field loses focus. Some "experts" recommend use focus() function. But what if I edit text in the middle of it? Any solutions? Or maybe native-base have compatible textfield component?

2

2 Answers

0
votes

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 )

0
votes

You must provide the InputField component as a prop so that its value is constant or put it outside the Item component, when it is inside another, every time the state of the upper level is updated, the lower level is forced to return. to start.

If your Input is inside an Item you are probably using a FlatList and your goal is to put it in the header.

You can try something like this:

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

Remember to put the styles that were in Item in View.