Skip to content
Mosaic
On this page

useResendSeconds

Returns the whole seconds left until resendAvailableAt, ticking every second, clamped between 0 and maxSeconds. Call it as useResendSeconds(resendAvailableAt, maxSeconds). Returns 0 when resendAvailableAt is undefined.

Use for

  • the seconds left on a resend cooldown, for display
  • a "Resend code in 30s" label

Practices

GuidancePractice
DoKeep resendAvailableAt in the machine, and derive the seconds in the view with this hook.
Don’tCount seconds down in state or a machine. Store the timestamp instead.

Examples

A resend label

TSX
const seconds = useResendSeconds(resendAvailableAt, 30);