我是一名新的 react 原生开发人员,我遇到了 TouchableHighlight 的问题,它总是显示错误“错误:React.Children.only 预计会收到单个 React 元素子项。” 此外,当我删除它时,它照常工作,我假设这个问题来自我的设备/vscode/浏览器。因为我已经遵循了https://reactnative.dev/docs/touchablehighlight的源代码,但仍然显示该错误。没有 TouchableHighlight 标记的
错误图像图像
这是我的代码
render() {
return (
<View style={styles.container}>
<TouchableHighlight onPress={this.onPress}>
<View style={styles.button}>
<Text>Touch Here</Text>
</View>
</TouchableHighlight>
<View style={[styles.countContainer]}>
<Text style={[styles.countText]}>
{this.state.count ? this.state.count : null}
</Text>
</View>
</View>
);}