0
我有一個TextInput,其樣式根據狀態發生更改。React Native:TextInput在樣式發生變化時丟失文本
<TextInput
autoCapitalize="characters"
defaultValue={this.props.name}
onChangeText={(text) => { this.handleChangeText(text); }}
onEndEditing={this.handleTextSubmit}
placeholder={this.props.dictionary.Identification__placeholder}
placeholderTextColor={color.WHITE}
ref={(component) => { this.textInput = component; }}
style={[
defaultStyles.input,
styles.input,
this.state.keyboardIsVisible && styles.inputSelected,
]}
underlineColorAndroid="rgba(0,0,0,0)"
/>
問題是當樣式改變時,它將擦除TextInput中的當前值。有沒有辦法解決這個問題?
handleTextChange更新狀態中的值。 'value = {this.state.inputText}'解決了我的問題。謝謝,我沒有這樣做。 –