Gathering detailed insights and metrics for react-downcount
Gathering detailed insights and metrics for react-downcount
Gathering detailed insights and metrics for react-downcount
Gathering detailed insights and metrics for react-downcount
npm install react-downcount
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
2 Stars
5 Commits
2 Watching
2 Branches
1 Contributors
Updated on 26 May 2019
HTML (51.63%)
JavaScript (39.1%)
CSS (9.26%)
Cumulative downloads
Total Downloads
Last day
-17%
39
Compared to previous day
Last week
-29%
225
Compared to previous week
Last month
17.3%
1,346
Compared to previous month
Last year
37.4%
16,392
Compared to previous year
3
28
React countdown component
1npm install --save react-downcount
or
1yarn add react-downcount
See live demo at codesandbox.io.
1import Countdown, { doubleDigit } from 'react-downcount'
Prop | Required | Default | Example | Description |
---|---|---|---|---|
endDate | yes | - | 1537637481962 - unix timestampor new Date('...') - Date object | Unix timestamp or Date object that sets the moment in time the Countdown is finished |
onCompleted | no | - | () => console.log('The countdown has completed') | Callback being invoked when the Countdown has reached its end |
useDays | no | true | true / false | If false , the remaining days are recalculated to hours, see more in examples section |
useHours | no | true | true / false | If false , the remaining horus are recalculated to minutes, see more in examples section |
useMinutes | no | true | true / false | If false , the remaining minutes are recalculated to seconds, see more in examples section |
className | no | - | string | <Countdown /> 's wrapper className |
children | no | defaultRenderer | ({ days, hrs, mins, secs, isCompleted }) => { ... } | If passed, children can only be a function that is used as a render callback to create custom <Countdown /> renderer |
1const endDate = new Date('2020-12-24') // Christmas, yay 2<Countdown endDate={endDate} />
produces e.g.
823 days 06:19:01
You can use the custom renderer to create arbitrary countdown outputs. You can control rendering each property based on it's value or create language mutations.
Each custom renderer is passed the following object { days, hrs, mins, secs, isCompleted }
.
1const endDate = new Date('2020-12-24') // Christmas, yay 2const countdownRenderer = ({ days, hrs, mins, secs, isCompleted }) => { 3 return isCompleted 4 ? 'Done' 5 : <Fragment>{days > 0 && `${days} days `}{hrs} hours {doubleDigit(mins)} minutes {doubleDigit(secs)} seconds</Fragment> 6} 7<Countdown endDate={endDate} />
produces e.g. 823 days 6 hours 15 minutes 37 seconds
or 6 hours 15 minutes 37 seconds
react-downcount
package exports doubleDigit
function that comes in handy when you want hour/minute/second values padded with leading zero. Just import it like so import { doubleDigit } from 'react-downcount'
Pass a callback as an onCompleted
property that gets invoked when the countdown ends.
1<Countdown endDate={...} onCompleted={() => { 2 console.log('The countdown has finished') 3}} />
You may wish not to convert hours to days / minutes to hours / seconds to minutes. You can control this behaviour with useDays
, useHours
and useMinutes
props.
e.g.
1<Countdown endDate={...} useDays={false} />
may produce 55 hours 30 minutes 19 seconds
instead of 2 days 7 hours 30 minutes 19 seconds
The same goes for useHours
and useMinutes
properties. These can be combined arbitrarily.
You can pass className
and all other properties to the <Countdown />
component.
e.g.
1<Countdown endDate={...} className="my-custom-class" onClick={(e) => { ... }} />
Javascript already comes with a pretty good set of functions that allow you easily set an endDate
.
Say you want the <Countdown />
to expire 3 hours in the future.
You can do it as follows:
1const endDate = new Date()
2endDate.setHours(endDate.getHours() + 3)
The beauty of it is that if it's 23:00 (11 PM) and you do this, it sets the hours to 2:00 (2 AM), but also increments the day. Same way if you do e.g.
1const endDate = new Date()
2endDate.setMinutes(endDate.getMinutes() + 100)
it adds 1 hour and 40 minutes to the endDate.
or you can just use current timestamp and add for instance 5 minutes manually, like so
1const endDate = Date.now() + 1000 * 60 * 5
MIT © MelkorNemesis
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
Found 0/5 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
133 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More