All Projects → amrlabib → React Timer Hook

amrlabib / React Timer Hook

Licence: mit
React timer hook

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Timer Hook

Use Timer
A timer hook for React
Stars: ✭ 113 (-4.24%)
Mutual labels:  timer, time, clock, countdown
Flipdown
⏰ A lightweight and performant flip styled countdown clock
Stars: ✭ 136 (+15.25%)
Mutual labels:  timer, clock, countdown
tm
timers and timeline
Stars: ✭ 31 (-73.73%)
Mutual labels:  time, clock, timer
React Countdown
React Component showing a countdown to certain date and time.
Stars: ✭ 58 (-50.85%)
Mutual labels:  timer, clock, countdown
Vue Clock2
vue clock component 😀
Stars: ✭ 67 (-43.22%)
Mutual labels:  time, component, clock
Flip Clock
A flip clock, timer and countdown made with Polymer
Stars: ✭ 69 (-41.53%)
Mutual labels:  timer, clock, countdown
Portable Snippets
Collection of miscellaneous portable C snippets.
Stars: ✭ 397 (+236.44%)
Mutual labels:  time, clock
React Countdown
A customizable countdown component for React.
Stars: ✭ 402 (+240.68%)
Mutual labels:  component, countdown
Easytimer.js
Easy to use Timer/Stopwatch/Countdown library compatible with AMD, ES6 and Typescript
Stars: ✭ 562 (+376.27%)
Mutual labels:  timer, countdown
Countdownlabel
Simple countdown UILabel with morphing animation, and some useful function.
Stars: ✭ 714 (+505.08%)
Mutual labels:  timer, countdown
Md Date Time Picker
An implementation of Material Design Picker components in vanilla CSS, JS, and HTML
Stars: ✭ 272 (+130.51%)
Mutual labels:  time, clock
React Laag
Hooks to build things like tooltips, dropdown menu's and popovers in React
Stars: ✭ 568 (+381.36%)
Mutual labels:  hook, component
Termdown
Countdown timer and stopwatch in your terminal
Stars: ✭ 749 (+534.75%)
Mutual labels:  timer, countdown
Oycountdownmanager
在cell中使用倒计时的处理方法, 全局使用一个NSTimer对象, 支持单列表.多列表.多页面.分页列表使用
Stars: ✭ 317 (+168.64%)
Mutual labels:  time, countdown
Peaclock
A responsive and customizable clock, timer, and stopwatch for the terminal.
Stars: ✭ 314 (+166.1%)
Mutual labels:  timer, clock
Timestamp
⏰ A better macOS menu bar clock.
Stars: ✭ 296 (+150.85%)
Mutual labels:  time, clock
Klock
Multiplatform Date and time library for Kotlin
Stars: ✭ 569 (+382.2%)
Mutual labels:  time, clock
Countdowntask
⌛️A countdown library for Android.
Stars: ✭ 64 (-45.76%)
Mutual labels:  timer, countdown
Truetime Android
Android NTP time library. Get the true current time impervious to device clock time changes
Stars: ✭ 1,134 (+861.02%)
Mutual labels:  time, clock
new-clock
The best clock app there is
Stars: ✭ 24 (-79.66%)
Mutual labels:  clock, timer

react-timer-hook

React timer hook is a custom react hook, built to handle timer, stopwatch, and time logic/state in your react component.

  1. useTimer: Timers (countdown timer)
  2. useStopwatch: Stopwatch (count up timer)
  3. useTime: Time (return current time)

Setup

yarn add react-timer-hook OR npm install --save react-timer-hook


useTimer - Demo

Example

import React from 'react';
import { useTimer } from 'react-timer-hook';

function MyTimer({ expiryTimestamp }) {
  const {
    seconds,
    minutes,
    hours,
    days,
    isRunning,
    start,
    pause,
    resume,
    restart,
  } = useTimer({ expiryTimestamp, onExpire: () => console.warn('onExpire called') });


  return (
    <div style={{textAlign: 'center'}}>
      <h1>react-timer-hook </h1>
      <p>Timer Demo</p>
      <div style={{fontSize: '100px'}}>
        <span>{days}</span>:<span>{hours}</span>:<span>{minutes}</span>:<span>{seconds}</span>
      </div>
      <p>{isRunning ? 'Running' : 'Not running'}</p>
      <button onClick={start}>Start</button>
      <button onClick={pause}>Pause</button>
      <button onClick={resume}>Resume</button>
      <button onClick={() => {
        // Restarts to 5 minutes timer
        const time = new Date();
        time.setSeconds(time.getSeconds() + 300);
        restart(time)
      }}>Restart</button>
    </div>
  );
}

export default function App() {
  const time = new Date();
  time.setSeconds(time.getSeconds() + 600); // 10 minutes timer
  return (
    <div>
      <MyTimer expiryTimestamp={time} />
    </div>
  );
}

Settings

key Type Required Description
expiryTimestamp number(timestamp) YES this will define for how long the timer will be running
onExpire Function No callback function to be executed once countdown timer is expired

Values

key Type Description
seconds number seconds value
minutes number minutes value
hours number hours value
days number days value
isRunning boolean flag to indicate if timer is running or not
pause function function to be called to pause timer
start function function if called after pause the timer will continue based on original expiryTimestamp
resume function function if called after pause the timer will continue countdown from last paused state
restart function function to restart timer with new expiryTimestamp

useStopwatch - Demo

Example

import React from 'react';
import { useStopwatch } from 'react-timer-hook';

function MyStopwatch() {
  const {
    seconds,
    minutes,
    hours,
    days,
    isRunning,
    start,
    pause,
    reset,
  } = useStopwatch({ autoStart: true });


  return (
    <div style={{textAlign: 'center'}}>
      <h1>react-timer-hook</h1>
      <p>Stopwatch Demo</p>
      <div style={{fontSize: '100px'}}>
        <span>{days}</span>:<span>{hours}</span>:<span>{minutes}</span>:<span>{seconds}</span>
      </div>
      <p>{isRunning ? 'Running' : 'Not running'}</p>
      <button onClick={start}>Start</button>
      <button onClick={pause}>Pause</button>
      <button onClick={reset}>Reset</button>
    </div>
  );
}

export default function App() {
  return (
    <div>
      <MyStopwatch />
    </div>
  );
}

Settings

key Type Required Description
autoStart boolean No if set to true stopwatch will auto start
offsetTimestamp number No this will define the initial stopwatch offset example: const stopwatchOffset = new Date(); stopwatchOffset.setSeconds(stopwatchOffset.getSeconds() + 300); this will result in a 5 minutes offset and stopwatch will start from 0:0:5:0 instead of 0:0:0:0

Values

key Type Description
seconds number seconds value
minutes number minutes value
hours number hours value
days number days value
isRunning boolean flag to indicate if stopwatch is running or not
start function function to be called to start/resume stopwatch
pause function function to be called to pause stopwatch
reset function function to be called to reset stopwatch to 0:0:0:0, you can also pass offset parameter to this function to reset stopwatch with offset, similar to how offsetTimestamp will offset the initial stopwatch time

useTime - Demo

Example

import React from 'react';
import { useTime } from 'react-timer-hook';

function MyTime() {
  const {
    seconds,
    minutes,
    hours,
    ampm,
  } = useTime({ format: '12-hour'});

  return (
    <div style={{textAlign: 'center'}}>
      <h1>react-timer-hook </h1>
      <p>Current Time Demo</p>
      <div style={{fontSize: '100px'}}>
        <span>{hours}</span>:<span>{minutes}</span>:<span>{seconds}</span><span>{ampm}</span>
      </div>
    </div>
  );
}

export default function App() {
  return (
    <div>
      <MyTime />
    </div>
  );
}

Settings

key Type Required Description
format string No if set to 12-hour time will be formatted with am/pm

Values

key Type Description
seconds number seconds value
minutes number minutes value
hours number hours value
ampm string am/pm value if 12-hour format is used

Deprecation Warning:

Starting from v1.1.0 and above default export useTimer is deprecated, your old code will still work but it is better to start using named exports { useTimer, useStopwatch, useTime }

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].