Media & time
Countdown
A countdown to a fixed moment.
Import
import { Countdown } from '@the_viveksingh/vivek-ui'Time until an event
Pass now to pin the reference time. That is what makes a countdown testable and keeps server and client markup identical on the first paint.
Pass `now` to pin the reference time, which is what makes a countdown testable and keeps server and client markup identical.
<Countdown to={launchDate} label="Time until v1.0" />Pick the units
<Countdown to={launchDate} format={['hours', 'minutes', 'seconds']} showLabels={false} />
<Countdown to={launchDate} hideZeroUnits label="Time until launch" />Props
Generated from the package's own type declarations, so this table cannot drift from the code.
| Prop | Type | Default | Description |
|---|---|---|---|
to required | Date | string | number | — | The moment being counted down to. |
format | readonly CountdownUnit[] | — | Which units to show. Order is normalised largest-first. Defaults to all four. |
onComplete | () => void | — | Fired once, when the countdown reaches zero. |
showLabels | boolean | — | Show the word under each number. Defaults to `true`. |
hideZeroUnits | boolean | — | Drop leading units that are still zero. |
now | Date | string | number | — | The clock for the FIRST render, on both sides of hydration. Pass a server timestamp and the server HTML contains real numbers that the client reproduces exactly. Omit it and the first render is a `--` placeholder instead: the component refuses to read the clock during render, because a server that renders at 12:00:03 and a browser that hydrates at 12:00:05 would produce different HTML and React would discard it with a hydration error. |
labels | Partial<Record<CountdownUnit, string>> | — | Override the visible unit words, e.g. for another language. |
label | string | — | Accessible name of the timer. Defaults to `'Time remaining'`. |
completeLabel | string | — | Announced instead of the digits once the countdown finishes. |
Every remaining prop is spread onto the root element, so all standard HTML and ARIA attributes work. className and style are merged with the library's own, never replaced, and the ref forwards to the root DOM node.
Rendering
Countdown declares 'use client' because it needs state, effects or event handlers. Importing it into a Server Component creates a client boundary at this component — everything above it stays on the server.