Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug when minute is more than 1, the countdown / interval will clear at 0:59 #2

Open
soemarko opened this issue Dec 17, 2022 · 0 comments

Comments

@soemarko
Copy link

Basically as titled, set the timer for 1:10, wait for a bit, and it'll stuck at 0:59.

The whole component is simple enough so I just copy/pasted it so it'll work without minute, and reformat the output.

  useEffect(() => {
    let countDown: number;
    if (isTimerActive) {
      countDown = setInterval(() => {
        if (seconds > 0) {
          setSeconds((seconds) => seconds - 1);
        }
      }, 1000);
    }

    if (!seconds) {
      setIsTimerActive(false);
    }
    return () => clearInterval(countDown);
  }, [seconds, isTimerActive]);

and

        <Text style={props.timerStyle}>
          {Math.floor(seconds / 60)}:
          {(seconds % 60) < 10 ? `0${(seconds % 60)}` : (seconds % 60)}
        </Text>

I can do a PR for this, or you should fix the setInterval function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant