Skip to content
function useNowSeconds(boundaries?): number;

The current Unix time in whole seconds, re-rendering only at the moments a caller names.

Pass the timestamps at which the rendered output changes (an expiry, the end of a freshness window) and the component re-renders when each one arrives, not once a second. Omit boundaries for relative text such as “5 minutes ago”, which updates on each minute. An empty array never re-renders. Every mounted caller shares one timer, and a boundary farther away than the browser’s maximum timeout is revisited until it arrives.

Parameters

ParameterTypeDescription
boundaries?readonly number[]Unix timestamps in seconds. Order and duplicates do not matter, and past values are ignored.

Returns

number

The second observed at mount or at the latest boundary; 0 while server rendering.

Example

const now = useNowSeconds([Number(loc.expirationTimestamp)]);
const expired = BigInt(now) >= loc.expirationTimestamp;