useCountDown

React State Hooks that return the minutes gracefully

Usage

import { useCountDown } from "@reactuses/core";

const Demo = () => {
  const now = new Date();
  const tomorrow = new Date();
  tomorrow.setDate(now.getDate() + 1);
  tomorrow.setHours(0, 0, 0, 0);
  const diffInSec = Math.floor((tomorrow.getTime() - now.getTime()) / 1000);

  // note: If your app is running in server side, must pass the same time as the client
  // this demo is not running in server side
  const [hour, minute, second] = useCountDown(diffInSec);
  return (
    <div suppressHydrationWarning={true}>{`${hour}:${minute}:${second}`}</div>
  );
};

Example

09:42:10

Type Declarations

export declare const getHMSTime: (timeDiff: number) => [string, string, string]
declare const useCountDown: (
  time: number,
  format?: (num: number) => [string, string, string],
  callback?: () => void
) => readonly [string, string, string]
export default useCountDown