ilokesto

DelayedFallback

DelayedFallback is a thin wrapper around usePendingDelay. It renders fallback while the hook returns true, and children otherwise.

This API is unreleased and is not included in @ilokesto/utilinent 1.2.1.

import { DelayedFallback } from '@ilokesto/utilinent';

function Results({ pending, result }: { pending: boolean; result: string }) {
  return (
    <DelayedFallback.section
      pending={pending}
      delay={200}
      minDuration={300}
      aria-busy={pending}
      aria-label="Search results"
      fallback={<span role="status">Updating results…</span>}
    >
      <p>{result}</p>
    </DelayedFallback.section>
  );
}

A request shorter than 200 ms leaves the current result visible. A longer request replaces it with the status for at least 300 ms from reveal, including any remaining hold after completion.

Props

PropTypeDefaultDescription
pendingbooleanRequiredWhether work is currently pending.
delaynumber200Delay before showing fallback, in milliseconds.
minDurationnumber300Minimum fallback duration from reveal, in milliseconds.
fallbackReactNodenullContent while delayed pending UI is visible.
childrenReactNode—Content before reveal and after the minimum hold ends.

The timing, option-update, zero-duration, SSR, and cleanup rules are identical to usePendingDelay.

Content and loading composition

Children remain mounted during the initial delay. They unmount when the fallback appears and mount again after the hold ends, even if pending has already become false. Do not place content that must preserve local state inside this replacement branch.

To keep results mounted, compose the hook with a separate status region as shown in its reference page. To render only a delayed indicator, omit children:

<DelayedFallback pending={pending} fallback={<span role="status">Loading…</span>} />

The base component adds no DOM wrapper. DelayedFallback.div, .section, and other proxy tags keep their wrapper mounted, forward host props and refs, and never forward timing props to the DOM. Registered targets use the delayedFallback category with the existing base registry fallback.

Supply accessible loading text and status semantics yourself. Use aria-busy={pending} for actual work rather than the delayed presentation state. The component does not automatically add ARIA attributes, disable actions, or handle Suspense.

On this page