MCPcopy Index your code
hub / github.com/alexkhismatulin/react-use-count-down

github.com/alexkhismatulin/react-use-count-down @1.1.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release 1.1.1 ↗ · + Follow
8 symbols 17 edges 11 files 0 documented · 0% updated 2y ago★ 7511 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

react-countdown-hook

Dead simple yet powerful countdown hook for React. Powered by requestAnimationFrame.

<a href="https://circleci.com/gh/alexkhismatulin/react-use-count-down">
    <img src="https://circleci.com/gh/alexkhismatulin/react-use-count-down.svg?style=svg" />
</a>
<a href="https://coveralls.io/github/alexkhismatulin/react-use-count-down?branch=master">
    <img src="https://coveralls.io/repos/github/alexkhismatulin/react-use-count-down/badge.svg?branch=master" />
</a>
<a href="https://www.npmjs.com/package/react-countdown-hook">
    <img src="https://img.shields.io/npm/v/react-countdown-hook.svg" />
</a>

Installation

Using npm:

$ npm install --save react-countdown-hook

Using yarn:

$ yarn add react-countdown-hook

Quick Start

import React from 'react';
import useCountDown from 'react-countdown-hook';

const initialTime = 60 * 1000; // initial time in milliseconds, defaults to 60000
const interval = 1000; // interval to change remaining time amount, defaults to 1000

const render = () => {
  const [timeLeft, { start, pause, resume, reset }] = useCountDown(initialTime, interval);

  // start the timer during the first render
  React.useEffect(() => {
    start();
  }, []);

  const restart = React.useCallback(() => {
    // you can start existing timer with an arbitrary value
    // if new value is not passed timer will start with initial value
    const newTime = 42 * 1000;
    start(newTime);
  }, []);

  return (
    <>


Time left: {timeLeft}



      <button onClick={restart}>
        Restart counter with 42 seconds
      </button>
    </>
  );
}

Note that this is a very basic usage. Check out more usage examples in playground or in the demo project

Documentation

[timeLeft, actions] = useCountDown(timeToCount, interval)

Parameters

Takes a default countdown time and interval time. * timeToCount {Number} Time in milliseconds that countdown should start with. Defaults to 60000 * interval {Number} Time in milliseconds representing the frequency that countdown should update with. Defaults to 1000

Return value

Returns an array with remaining time and actions object. * timeLeft {Number} Remaining countdown time in milliseconds * actions.start {Function} Start or restart a countdown. Takes time in milliseconds to start with. * actions.reset {Function} Resets a countdown to initial state * actions.pause {Function} Pauses a countdown * actions.resume {Function} Resumes a paused countdown

Contributing

Feel free to submit any issues or pull requests.

License

MIT

Extension points exported contracts — how you extend this code

Core symbols most depended-on inside this repo

Shape

Method 4
Function 2
Interface 2

Languages

TypeScript100%

Modules by API surface

typings.d.ts6 symbols
src/index.js2 symbols

For agents

$ claude mcp add react-use-count-down \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page