1.6.1 • Published 4 years ago

use-moment-countdown v1.6.1

Weekly downloads
275
License
MIT
Repository
github
Last release
4 years ago

useCountdown

check out my explanatory blog post here

a react hook for creating countdown timers with moment.js

NPM JavaScript Style Guide

Install dependencies

npm install --save moment

Install use-moment-countdown

npm install --save use-moment-countdown

Usage

timer set in minutes

import React from "react";

import { useCountdown } from "use-moment-countdown";

const App = () => {
  const { start, time } = useCountdown({ m: 10 });
  return <div onClick={start}>{time.format("hh:mm:ss")}</div>;
};

export default App;

timer set in hours

import React from "react";

import { useCountdown } from "use-moment-countdown";

const App = () => {
  const { start, time } = useCountdown({ h: 1 });
  return <div onClick={start}>{time.format("hh:mm:ss")}</div>;
};

export default App;

timer set in seconds

import React from "react";

import { useCountdown } from "use-moment-countdown";

const App = () => {
  const { start, time } = useCountdown({ s: 30 });
  return <div onClick={start}>{time.format("hh:mm:ss")}</div>;
};

export default App;

timer set in combination of hours, minutes, and seconds

import React from "react";

import { useCountdown } from "use-moment-countdown";

const App = () => {
  const { start, time } = useCountdown({ h: 1, m: 20, s: 30 });
  return <div onClick={start}>{time.format("hh:mm:ss")}</div>;
};

export default App;

recurring timer

import React from "react";

import { useCountdown } from "use-moment-countdown";

const App = () => {
  const { start, time } = useCountdown({ s: 30 }, {recurring: true});
  return <div onClick={start}>{time.format("hh:mm:ss")}</div>;
};

export default App;

onDone callback when timer ends

import React from "react";

import { useCountdown } from "use-moment-countdown";

const App = () => {
  const myOnDoneCallback = () => alert("Your timer has finished!")
  const { start, time } = useCountdown({ s: 30 }, {onDone: myOnDoneCallback});
  return <div onClick={start}>{time.format("hh:mm:ss")}</div>;
};

export default App;

This hook is created using create-react-hook.

1.6.1

4 years ago

1.5.3

4 years ago

1.6.0

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.5.2

4 years ago

1.5.1

4 years ago

1.5.0

4 years ago

1.4.0

4 years ago

1.3.0

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago