带状态的React-Native TextInput无效

时间:2018-08-30 07:33:20

标签: reactjs react-native textinput

代码:

<TextInput
      style={{height: 40, borderColor: 'gray', borderWidth: 1}}
      onChangeText={(text) => {
          const newText = text.replace(/[^\d]+/, '');
          this.setState({inputValue: newText})
      }}
      value={this.state.inputValue}
      keyboardType='numeric'
/>

我希望用户只能输入数字,其他将被替换。 但实际上没有效果。

ios> 10

“反应”:“ 16.3.1”,

“ react-native”:“ ^ 0.55.3”,

running result

1 个答案:

答案 0 :(得分:0)

我站在一边测试了您的样品,它运作良好:https://snack.expo.io/@sanjar/so52091526

您是否在构造函数中设置了状态的默认值?