具有状态的React-Native TextInput无效

问题描述 投票:0回答:1

代码:

<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

reactjs react-native textinput
1个回答
0
投票

我在你身边测试了你的样品并且效果很好:https://snack.expo.io/@sanjar/so52091526

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

© www.soinside.com 2019 - 2024. All rights reserved.