[ad_1]
I have a countdown timer set at every second. Every time I would reset the counter and choose another period to countdown, the previous timer keeps counting and will have multiple timers in the background. I tried to reset the timer.
How can I stop the timer each time I go back and choose another period.
Question : You advise me to use react-native-countdown-component or that script?
Ps: I need it to push Notification.
Here is my code bellow:
useEffect(() => {
if (isMounted) {
phaseDay.current = []
clearInterval(intervalRef.current)
fetchData()
} return () => {
isMounted.current = false;
}
}, [itemType])
useEffect(() => {
startTimer()
return () => {
if (intervalRef.current) clearInterval(intervalRef.current)
}
}, [intervalRef.current])
const startTimer = () => {
let { total, remainingDay, remainingHour, remainingMinute, remainingSecond } = calculateTimeLeft()
const id = setInterval(() => {
if (total > 0) {
setTimer([
..
} else {
setTimer([])
clearInterval(intervalRef.current)
setPlantType(false)
setItemType([])
}
handlerAirNotification()
}, 1000);
intervalRef.current = id
}
const onReset = () => {
return Alert.alert(
"..",
"..",
[
{
text: "Oui",
onPress: () => {
if (intervalRef.current) {
clearInterval(intervalRef.current)
isMounted.current = false
setPlantType(false)
setSeries([])
setTimerReset(true)
navigation.navigate('Home')
}
},
},...
reactjs
[ad_2]