1.0.12 • Published 9 months ago

use-remaining-time v1.0.12

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

Welcome to use-remaining-time 👋

Version Documentation Maintenance License: MIT

React hook that returns remaining time in hh:mm:ss format

Install

npm i use-remaining-time

Example

const Timer = () => {
  const hourCountdown = 60 * 60;
  const { timeString, secondsRemaining, isPaused, resetTimer, setIsPaused } =
    useRemainingTime(hourCountdown, false, () =>
      console.log("Countdown finished")
    );
  return (
    <div>
      <h1>Countdown: {timeString}</h1>
      <button onClick={resetTimer}>Reset countdown</button>
      <button onClick={() => setIsPaused(true)}>Pause countdown</button>
    </div>
  );
};

Configuration

Hook takes folowing options

NameTypeDescription
initialSecondsNumberStart of timer in second
initialPausedBooleanInitial pause state
onCompleteFunction?Callback when timer hits 0 seconds remaining (optional)

Properties

Hook returns following properties:

NameTypeDescription
timeStringStringTime remaining in hh:mm:ss format
secondsRemainingNumberThe time remaining in seconds
isPausedBooleanWhether the timer is currently ticking down
setIsPausedFunctionFunction to pause or resume timer. Requires boolean parameter
resetTimerFunctionA function to reset timer to initialSeconds accepts boolean parameter .

Show your support

Give a ⭐️ if this project helped you!

1.0.12

9 months ago

1.0.11

9 months ago

1.0.10

11 months ago

1.0.9

11 months ago

1.0.8

11 months ago

1.0.7

11 months ago

1.0.6

11 months ago

1.0.5

11 months ago

1.0.4

11 months ago

1.0.3

11 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago