【发布时间】:2021-06-12 15:28:23
【问题描述】:
我正在使用 react-native 的 TouchableOpacity。代码是:
<TouchableOpacity onPress={onPress}>
<Text style={styles.supplementItem}>{item.item}</Text>
</TouchableOpacity>
OnPress 函数在哪里:
const onPress = () => (
// eslint-disable-next-line no-sequences
<Text style={styles.supplementItem}>Hello</Text>
this.setState({tempKey: tempKey + 1})
);
我看了看:this question 并尝试做喜欢它。但这不起作用。我将状态设置如下:
constructor(props) {
super(props);
this.state = {
tempKey: 0,
};
}
请帮助我做错了什么。
【问题讨论】:
标签: react-native components touchableopacity onpress