useTimeAgo
Format a date as relative time, such as "3 minutes ago" or "in 2 days", and keep it up to date. It uses Intl.RelativeTimeFormat and schedules each update for the moment the text changes. The text depends on the current time, so a server render can differ from the client; add suppressHydrationWarning to the element or render it on the client only.
- Level
- Basic
- Since
- v2.1.0
import {useTimeAgo} from '@zenuilabs/react-hooks';Loading demo_
More in Time & Motion
Time & MotionIntermediateuseAnimationFrameRun a callback on every animation frame with the time since the previous frame. Use it for canvas drawing, games and imperative animations where movement should be scaled by elapsed time.Time & MotionIntermediateuseCountdownCount down to a date or through a duration and expose days, hours, minutes and seconds. Time left is computed from the clock rather than by counting ticks, so it does not drift in background tabs. When the target is a Date, the first render depends on the current time, so render it on the client only to avoid a hydration mismatch.Time & MotionBasicuseIntervalRun a callback on a fixed interval that pauses when the delay is null. The latest callback is always called, so it can read fresh state without restarting the timer.