rooks
Version:
Collection of awesome react hooks
30 lines (29 loc) • 1.15 kB
TypeScript
import type { Temporal } from "@js-temporal/polyfill";
type TemporalElapsedPrecision = "second" | "minute";
type TemporalElapsedOptions = {
/**
* The instant from which elapsed time is measured.
* Accepts a Temporal.Instant, an ISO 8601 string, or epoch milliseconds.
* Defaults to the instant the hook first renders on the client.
*/
since?: Temporal.Instant | string | number;
/**
* How often the elapsed duration updates.
* @default "second"
*/
precision?: TemporalElapsedPrecision;
};
/**
* useTemporalElapsed
* Returns the elapsed duration since a given start instant, ticking at
* the requested precision boundary.
*
* On the server this hook returns null so hydration remains deterministic.
* Returns null while the Temporal polyfill is loading.
*
* @param options Configuration with an optional start instant and precision
* @see https://rooks.vercel.app/docs/hooks/useTemporalElapsed
*/
declare function useTemporalElapsed(options?: TemporalElapsedOptions): Temporal.Duration | null;
export { useTemporalElapsed };
export type { TemporalElapsedOptions, TemporalElapsedPrecision };