答案 0 :(得分:1)
设法解决:
class Game extends React.Component {
state = {
score: 0,
isButtonClickable: true
}
onPress() {
const {isButtonClickable, score} = this.state
if (isButtonClickable) {
setTimeout(() => {
this.setState({isButtonClickable: true})
}, 2000)
}
const newScore = isButtonClickable ? score + 1 : 0
this.setState({isButtonClickable: false, score: newScore})
}
render() {
<View>
<View>{this.state.score}</View>
<Button onPress={() => this.onPress()}</Button>
</View>
}
}