【发布时间】:2021-08-06 11:54:20
【问题描述】:
我是一名新的 react 原生开发人员,我遇到了 TouchableHighlight 问题,它总是显示错误“错误:React.Children.only 预计会收到单个 React 元素子项。”此外,当我删除它时,它照常工作,我假设这个问题是否来自我的设备/vscode/浏览器。因为我已经按照https://reactnative.dev/docs/touchablehighlight 的源代码,但仍然显示该错误。
Error image
Image without TouchableHighlight tag
这是我的代码
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>
);}
【问题讨论】:
-
您能在小吃博览会上向我们展示您的代码吗?
-
你能把确切的代码发给我们吗?
标签: react-native touchablehighlight