question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

autoStart false, countdown shortly shows seconds passed before rerendering and starting properly

See original GitHub issue

This issue is probably related to hooks but here goes: My countdown is set to autostart false and to run for 60 seconds, when I start the timer, I first reset the date and key prop, otherwise the countdown would start running with the already passed seconds (e.g. if I wait 3 seconds before starting the countdown, the countdown would start at 0:57 instead of 1:00).

The parent component sets the “startTimer” prop to true, which in return sets autoStart to true as well:

useEffect(() => {
  let newCountdown = Date.now() + durationInSeconds * 1000;
  setCountdownKey(newCountdown);
  setCountdownDate(newCountdown);
}, [startTimer]);

.
.
.

<Countdown
  key={countdownKey}
  date={countdownDate}
  autoStart={startTimer}
  renderer={({ minutes, seconds }) => (
    <span>
      {minutes}:{zeroPad(seconds)}
    </span>
  )}
/>

The only issue I have right now is, once I start the countdown, it first jumps to the time passed (the same as described above with e.g. waiting 3 seconds, jumping to 0:57) and then resets correctly to 1:00 and goes down from there.

Is there a reason for the time jump with autostart false or am I not properly resetting the date and key before starting?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
christianstrangcommented, Nov 28, 2019

Thank you for your help! I don’t know what happened but I removed the fakeRenderer approach and it just works (the same code didn’t work before without a timejump). Not sure if there was some kind of caching involved or I didn’t handle sideeffects properly, but my current code now works as intended 😃

0reactions
ndresxcommented, Nov 27, 2019

It’s a bit hard to reproduce this now, but if you got anything to share in that direction to look into a bit more it would be great. I’m not quite sure how the date could get stale within the countdown and then update with this jump. Thank you already though for the feedback!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Let's Build a Game - React Succinctly Ebook | Syncfusion
Here's how this game works: The first UI will show an empty grid (no colors) and a Start Game button. Clicking that button...
Read more >
React-Quickly_-Painl..
“React Quickly is a one-stop shop for anyone who wants a guided introduction to. React and the ecosystem of tools, concepts, and libraries...
Read more >
What's New / Product Roadmap - ShortPoint Blog
ShortPoint Product roadmap, release notes and what's new in the latest releases. You can also check what we are plannig to release and...
Read more >
history
A query module can enable these hooks by passing an array for $hookData to ... Don't forget to always back up your database...
Read more >
Newtek 3Play 425 - Rackcdn.com
When you power up your NewTek 3Play™ system, the Startup Screen appears. ... to display a countdown to the end of the event...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found