rooks
Version:
Collection of awesome react hooks
36 lines (35 loc) • 1.41 kB
TypeScript
import type { Temporal } from "@js-temporal/polyfill";
type TemporalCountdownPrecision = "second" | "minute";
type TemporalCountdownOptions = {
/**
* The target instant to count down to.
* Accepts a Temporal.Instant, an ISO 8601 string, or epoch milliseconds.
*/
target: Temporal.Instant | string | number;
/**
* How often the remaining duration updates.
* @default "second"
*/
precision?: TemporalCountdownPrecision;
};
type TemporalCountdownResult = {
/** Remaining duration until the target. Zero when the target has passed. */
remaining: Temporal.Duration;
/** Whether the target instant has been reached or passed. */
done: boolean;
};
/**
* useTemporalCountdown
* Returns the remaining duration until a target instant, ticking at
* the requested precision boundary. Stops automatically once the
* target is reached.
*
* On the server this hook returns null so hydration remains deterministic.
* Returns null while the Temporal polyfill is loading.
*
* @param options Configuration with a target instant and optional precision
* @see https://rooks.vercel.app/docs/hooks/useTemporalCountdown
*/
declare function useTemporalCountdown(options: TemporalCountdownOptions): TemporalCountdownResult | null;
export { useTemporalCountdown };
export type { TemporalCountdownOptions, TemporalCountdownPrecision, TemporalCountdownResult, };