【问题标题】:react-native android: TextInput briefly ignores value propreact-native android:TextInput短暂地忽略了value prop
【发布时间】:2018-08-23 02:42:07
【问题描述】:

这是在带有 react-native v0.55.4 的 android 上。

<TextInput
  value="should always be this value"
/>

当我在这个 TextInput 中输入内容时,文本会短暂更新为我输入的任何新文本,然后再返回显示“应该始终是这个值”。

例如,如果我输入“X”,文本将短暂更新为“应该始终是这个值X”,然后返回到“应该始终是这个值”,从而在 TextInput 内部产生抖动。

编辑:文档解决了这个问题:https://facebook.github.io/react-native/docs/textinput#value

【问题讨论】:

  • 您能提供更多代码吗?你有任何状态可以用作价值吗?

标签: android reactjs react-native


【解决方案1】:

仅基于该短代码n-p,您需要将值设置为状态属性。

constructor(props) {
 super(props);
 this.state = {
   textInput: 'Should always be this value'
 }
}

还有你的文字输入

<TextInput
 value={this.state.textInput}
 onChangeText={text => this.setState({ textInput: text }) }
/>

这里有一些docs

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-05-09
  • 1970-01-01
  • 1970-01-01
  • 2020-11-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多