2017-04-13 41 views
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中的當前值。有沒有辦法解決這個問題?

回答

1

handleTextChange在做什麼?你應該有一個value屬性,如value={this.state.inputText},並有handleTextChange更新該值。

+0

handleTextChange更新狀態中的值。 'value = {this.state.inputText}'解決了我的問題。謝謝,我沒有這樣做。 –

相關問題