1.0.4 • Published 1 year ago

use-react-timer v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

use-react-timer

All Contributors

A minimal timer hook, countdown time for react and react native. Just <1kB

Use case

Installation

npm

npm install use-react-timer

yarn

yarn add use-react-timer

Live examples (Sandbox)

Edit hovndn

useTimer

useTimer(endAt) returns a object, the values of the object is day, hour, min, sec, isRunning. Argument endAt is Date type, the date that you want to compare to now time for timer.

Apply timer with useTimer function

Example:

import React from "react";
import { useTimer } from "use-react-timer";

let endAt = new Date();
endAt.setDate(new Date().getDate() + 2);

const Timer = () => {
  const { day, hour, min, sec, isRunning } = useTimer(endAt);
  return (
    <div className="timer">
      <span>{day}{':'}</span>
      <span>{hour}{':'}</span>
      <span>{min}{':'}</span>
      <span>{sec}</span>
    </div>
  );
};

export default Timer;

API

const { day, hour, min, sec, isRunning } = useTimer(endAt); | name | type | description | | ------------------------------ | ---------------------------------- | -------------------------------------------------------------------| | day | string | day of countdown | | hour | string | hour of countdown | | min | string | minute of countdown | | sec | string | second of countdown | | isRunning | boolean | returns a boolean value whether countdown is running or tap to end |

License

MIT

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago