Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keyboard disappears on every key press in React Native

I want to map key value pairs in react native. The value being editable text entry. The mapped components show up fine, but when I try to edit the TextInput, the keyboard disappears when i type the first letter. Don't know whats causing the problem.

If i just put a TextInput in the parent element, it works absolutely fine but doesn't work when I use the map function.

 <View style={styles.main}>
        <View>
            {this._getDetailElements()}
        </View>
 </View>

_getDetailElements() function

 _getDetailElements = () => {

    return Object.keys(this.state.data).map(elem => (
        <View key={shortid.generate()} style={styles.element}>
                <TextInput
                editable={this.state.editable}
                onChangeText={text => this.setState({seletedText: text})}
                value={this.state.selectedText}
                /> 
        </View>
    )
    );
}
like image 302
Ashish Gupta Avatar asked Feb 09 '19 08:02

Ashish Gupta


1 Answers

i think you should just change the value to defaultValue Like this :

    <TextInput
        editable={this.state.editable}
        onChangeText={text => this.setState({seletedText: text})}
        defaultValue={this.state.selectedText}
    />

Good luck

like image 102
MoHammaD ReZa DehGhani Avatar answered Oct 19 '22 03:10

MoHammaD ReZa DehGhani