我是新来的学习反应,和/阵营和本地人都遇到了以下问题。当点击<TouchableWithoutFeedback>
元素时,视图不会增加。下面阵营本地增量州onPress
代码:
class SingleHabit extends Component {
constructor() {
super();
this.state = {count: 0};
}
_incrementCount() {
this.setState = ({
count: count + 1
});
}
render() {
return (
<TouchableWithoutFeedback onPress={() => this._incrementCount() }>
<View
style= {[
styles.singleHabit,
{backgroundColor: this.props.color}
]}
>
<Text style={styles.habitNameText}>{this.props.text}</Text>
<Text style={styles.countText}>{this.state.count}</Text>
</View>
</TouchableWithoutFeedback>
);
}
}
此外,在自主学习的兴趣,如果有,反正你会重构这个(或只需更好的做事方式),我很想听听!
谢谢,这个工作! +感谢您的良好做法建议:) – Amz