All Projects → bradgarropy → use-countdown

bradgarropy / use-countdown

Licence: MIT license
⏳ useCountdown hook

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to use-countdown

Termdown
Countdown timer and stopwatch in your terminal
Stars: ✭ 749 (+848.1%)
Mutual labels:  countdown
Use Timer
A timer hook for React
Stars: ✭ 113 (+43.04%)
Mutual labels:  countdown
React Countdown Circle Timer
Lightweight React/React Native countdown timer component with color and progress animation based on SVG
Stars: ✭ 220 (+178.48%)
Mutual labels:  countdown
Snore
sleep with feedback
Stars: ✭ 47 (-40.51%)
Mutual labels:  countdown
Flip Clock
A flip clock, timer and countdown made with Polymer
Stars: ✭ 69 (-12.66%)
Mutual labels:  countdown
Ngx Countdown
Simple, easy and performance countdown for angular
Stars: ✭ 133 (+68.35%)
Mutual labels:  countdown
Easytimer.js
Easy to use Timer/Stopwatch/Countdown library compatible with AMD, ES6 and Typescript
Stars: ✭ 562 (+611.39%)
Mutual labels:  countdown
SyoTimer
jQuery plugin of countdown on html-page
Stars: ✭ 18 (-77.22%)
Mutual labels:  countdown
Countdownbutton
⏳A button component with a countdown function
Stars: ✭ 87 (+10.13%)
Mutual labels:  countdown
Countdownlist
CountDown 倒计时的各种花式实现
Stars: ✭ 222 (+181.01%)
Mutual labels:  countdown
React Native Timer Countdown
⏱ A minimal and customizable countdown timer for React Native (iOS and Android)
Stars: ✭ 53 (-32.91%)
Mutual labels:  countdown
Countdowntask
⌛️A countdown library for Android.
Stars: ✭ 64 (-18.99%)
Mutual labels:  countdown
Flipdown
⏰ A lightweight and performant flip styled countdown clock
Stars: ✭ 136 (+72.15%)
Mutual labels:  countdown
Rn Countdown
⏰ 纯 JavaScript 实现的针对 React Native App 的倒计时组件。
Stars: ✭ 19 (-75.95%)
Mutual labels:  countdown
CircularCountdown
Android library to create a circular countdown, fully written in Kotlin
Stars: ✭ 24 (-69.62%)
Mutual labels:  countdown
Countdownlabel
Simple countdown UILabel with morphing animation, and some useful function.
Stars: ✭ 714 (+803.8%)
Mutual labels:  countdown
React Timer Hook
React timer hook
Stars: ✭ 118 (+49.37%)
Mutual labels:  countdown
sku-algorithm
商品多规格选择-sku算法
Stars: ✭ 108 (+36.71%)
Mutual labels:  react-hook
react-use-countdown
React hook for countdown state.
Stars: ✭ 19 (-75.95%)
Mutual labels:  countdown
React Native Countdown Component
React Native CountDown
Stars: ✭ 193 (+144.3%)
Mutual labels:  countdown

useCountdown hook

version downloads size github actions codecov typescript contributing contributors discord

React hook countdown timer. As seen on my Twitch streams.

next link

📦 Installation

This package is hosted on npm.

npm install @bradgarropy/use-countdown

🥑 Usage

In any React component, import useCountdown, then call it like any other hook. The returned countdown value will update every second with the remaining time.

import useCountdown from "@bradgarropy/use-countdown"

const App = () => {
    const countdown = useCountdown({
        minutes: 1,
        seconds: 30,
        format: "mm:ss",
        onCompleted: () => console.log("onCompleted"),
    })

    console.log(countdown)

    // {minutes: 1, seconds: 30, formatted: "01:30", ...}
    // {minutes: 1, seconds: 29, formatted: "01:29", ...}
    // {minutes: 1, seconds: 28, formatted: "01:28", ...}
    // ...
    // {minutes: 0, seconds: 0, formatted: "00:00", ...}
    // onCompleted()
}

📖 API Reference

useCountdown({minutes, seconds})

Name Required Default Example Description
minutes false 0 1 Countdown minutes.
seconds false 0 30 Countdown seconds.
format false mm:ss mm:ss:SS Format string (reference).
onCompleted false undefined function Function to call when countdown completes.

Starts a countdown timer based on the number of minutes and seconds provided. The returned countdown object updates once per second and stops when the timer hits zero.

The format parameter is a date-fns format string.

If provided, the onCompleted function will be called when the countdown completes.

Here are some examples of how to call useCountdown.

const countdown = useCountdown({
    minutes: 1,
    seconds: 30,
    format: "mm:ss:SS",
    onCompleted: () => console.log("onCompleted"),
})

const countdown = useCountdown({
    minutes: 5,
    onCompleted: () => console.log("onCompleted"),
})

const countdown = useCountdown({seconds: 10, format: "mm:ss:SS"})

The return object is updated every second until the countdown timer ends.

Name Type Example Description
minutes number 1 Remaining minutes.
seconds number 30 Remaining seconds.
formatted string 01:30 Formatted remaining time.
isActive boolean true Indicates that the countdown is active, either running or paused.
isInactive boolean false Indicates that the countdown is inactive, and has finished counting down.
isRunning boolean true Indicates that the countdown is running.
isPaused boolean false Indicates that the countdown is paused.
pause function function Pauses the countdown.
resume function function Resumes the countdown.
reset function function Resets the countdown.

Here is an example of the returned object.

{
    minutes: 1,
    seconds: 30,
    formatted: "01:30",
    isActive: true,
    isInactive: false,
    isRunning: true,
    isPaused: false,
    pause: () => void,
    resume: () => void,
    reset: (time?: Time) => void,
}

Questions

🐛 report bugs by filing issues
📢 provide feedback with issues or on twitter
🙋🏼‍♂️ use my ama or twitter to ask any other questions

Contributors

Brad Garropy
Brad Garropy

💻 📖 ⚠️ 🚇
Matthew Scholta
Matthew Scholta

💻 📖
James Q Quick
James Q Quick

🤔 📓
Steven Hofheins
Steven Hofheins

📝
Jack Reiker
Jack Reiker

🤔 📓
Mehdi Makhloufi
Mehdi Makhloufi

🤔 📓
Daniel Badir
Daniel Badir

🐛 🤔 📓
Florin Cosmin
Florin Cosmin

💻
Nick DiMatteo
Nick DiMatteo

🐛
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].