Warning: Failed prop type: Invalid prop value of type number supplied to Textinput, expected string

版权声明:我写的你不能转载,但是你可以复制啊。复制记得加关注啊(迷之微笑)。 https://blog.csdn.net/quhongqiang/article/details/88837813

react-native 使用TextInput标签时会遇到这个警告:

Warning: Failed prop type: Invalid prop value of type number supplied to Textinput, expected string in Textinput (at Appointmentnumber is: 112) in Appointmentnumber(created by Context. Consumen)in withnavigation(Appointmentnumber)(created bySceneview

在道具中你传递的是数值,你必须以字符串的形式传递它,所以这样改进一下代码:

<TextInput
  style={styles.textinput}
  placeholder="站厅预约人数"
  placeholderTextColor = "#cccccc"
  keyboardType = "numeric"
  value={`${this.state.num}`} //这里改进一下就OK
  onChangeText={(num)=> {this.setState({num})}}
/>

猜你喜欢

转载自blog.csdn.net/quhongqiang/article/details/88837813