# 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

- Don't: Delay a spinner with `setTimeout`. Use this hook instead.
- Don't: Reach for it inside a button. `SubmitButton` already spin-delays its spinner.

## Options

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `delay` | `number` | `150` | Wait this long before showing the value. `0` shows it straight away. |
| `minDuration` | `number` | `400` | Once shown, keep a value up at least this long, counted from when the first value appeared, not from a later swap. |

## Examples

### Delay a pending flag

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

## Related

- `SubmitButton`
- [Spinner](/docs/components/spinner.md)
