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.

The Countdown "STOPPED" when passing variables to the "date" prop.

See original GitHub issue

I have a component looks like this:

function PracticeInfo({ totalQuestion, timeTest }) {
  return (
    <Grid.Row verticalAlign="middle">
      <Grid.Column width={2} textAlign="center">
        <p>
          <span className="font-semibold text-xl">
            <Countdown
              daysInHours
              date={Date.now() + timeTest * 60000}
            />
          </span>
        </p>
      </Grid.Column>
      <Grid.Column width={12} textAlign="center">
        <p>
          Total:{' '}
          <span className="font-semibold">{totalQuestion}</span>
        </p>
        <Progress value="3" total={totalQuestion} indicating progress="ratio" />
      </Grid.Column>
      <Grid.Column width={2} textAlign="center">
        <Button color="green" inverted>
          Submit
        </Button>
      </Grid.Column>
    </Grid.Row>
  );
}

As you can see, I tend to use the timeTest prop passing to the date prop of Countdown component. But it stuck at the beginning (as the status “STOPPED”). Mapping the prop to other variables didn’t work also.

But if I passing number into it, it’s work fine. Eg: Date.now() + 60 * 60000

Please help!

Issue Analytics

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

github_iconTop GitHub Comments

4reactions
ndresxcommented, Oct 19, 2020

ok, 0 would make it stop (complete) immediately in its current implementation. I’m still contemplating whether it’s better to also restart the countdown again when a date in the future is provided in such cases, but it’s not there right now.

What you could do in the meantime is to pass the date as a key which would also restart the countdown whenever this key/date changes, but on a React component level. Alternatively, you could use the API to restart it again whenever/wherever you change timeTest.

1reaction
beewithucommented, Oct 19, 2020

I tried the API and it’s working now. Thanks for your help.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to pass props correctly to react-countdown component
I am using the package react-countdown and I am hoping to pass in a prop and use that prop as the initial state...
Read more >
A customizable countdown component for React. - GitHub
onPause. onPause is a callback and triggered every time the countdown is paused. It receives a time delta object as the first argument....
Read more >
How to Create a Countdown Timer with React Hooks
In this tutorial, you will create a countdown timer using React hooks to update state and manage side effects in a React component....
Read more >
How to create a countdown timer using React Hooks
It displays each of the values(days, hours, minutes, and seconds) using a component called DateTimeDisplay that we create now. But notice the ...
Read more >
Bento Date Countdown | bentojs.dev
Specifies whether to stop the timer when it reaches 0 seconds. The value can be set to stop (default) to indicate the timer...
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