Skip to content
Mosaic
On this page

useSpinDelay

Spin-delays a nullable value. Returns null until value stays non-null and unchanged longer than delay; a new value restarts the wait. Once shown, it keeps a value up until at least minDuration after it first appeared. Swapping to another non-null value does not restart minDuration. Call it as useSpinDelay(value, options?).

Use for

  • a spinner that should not flash or flicker
  • a pending indicator that stays up long enough to read

Practices

GuidancePractice
Don’tDelay a spinner with setTimeout. Use this hook instead.
Don’tReach for it inside a button. SubmitButton already spin-delays its spinner.

Options

PropTypeDescription
delaynumberWait this long before showing the value. 0 shows it straight away.Default: 150
minDurationnumberOnce shown, keep a value up at least this long, counted from when the first value appeared, not from a later swap.Default: 400

Examples

Delay a pending flag

TSX
const showSpinner = useSpinDelay(isPending ? true : null) !== null;