0
Each time I click a button, I want to add +1 min to the timer.
<Button
onPress={this.somarUmMinuto}
title="Somar 1 minuto"
color="#007FFF"
accessibilityLabel="Somar 1 minuto"
/>
Code used to set the countdown:
iniciarCronometro() {
var intervalId = setInterval(this.somarUmSegundo, 1000);
this.setState({
intervalId: intervalId,
});
}
somarUmSegundo() {
let segundos = this.state.contadorSegundo;
let minutos = this.state.contadorMinuto;
minutos == 1 || segundos > 0;
if (segundos == 0) {
segundos = 59;
minutos = minutos - 1;
} else {
segundos = segundos - 1;
}
this.setState({
contadorSegundo: segundos,
contadorMinuto: minutos,
});
}
I need to increment the event to add +1 min to the timer, either already finished or in progress in the count.
Countdown timer lasts 1 minute.
See if this code helps: http://jsfiddle.net/alnitak/aBWce/
– Laércio Lopes
You have already separated the minutes and seconds (counterNumber and counterNumber), I do not understand what is really the problem. Don’t just go into the Inuto counter and increment?
– JrD
@Jrd tried to directly increment the minute counter, but error. I used code Let sum = (this.counterMinuto +1);
– Philipe Said
@Philipesaid Your Philipesaid counter is in the state of the application, so to access it you need to use this.state. In place of this code you presented try to add Let = this.state.counterMinuto + 1
– JrD
@Jrd Keeps giving error ( Undefined is not an Object ( evaluating'this.state.counterMinuto') ).
– Philipe Said
@Philipesaid You’re probably losing context... bind your method so you can access the state through this. Your onPress would look like this onPress={this.somarUmMinuto.bind(this)}
– JrD
@Jrd The error no longer happens. However, it does not execute the value increment.
– Philipe Said
@Philipesaid Please update your code there to see what happens, these comments are already getting too long
– JrD