platform-bible-react
    Preparing search index...

    Type Alias RetryablePromiseState<T>

    What useRetryablePromise reports about the fetch it is driving.

    type RetryablePromiseState<T> = {
        data: T | undefined;
        hasError: boolean;
        hasSettled: boolean;
        isLoading: boolean;
        refetch: () => void;
    }

    Type Parameters

    • T
    Index

    Properties

    data: T | undefined

    The most recently resolved value, or undefined before one arrives.

    A rejection leaves an already-resolved value alone (usePromise does not wipe it), so a caller whose fetch can fail after having succeeded should decide whether a stale value or an error state serves its user better, rather than assuming hasError means there is nothing to show.

    hasError: boolean

    Whether the last fetch rejected. Distinct from an absent data: a caller reading only data cannot tell "the fetch failed" from "the answer is genuinely nothing", which is the distinction that lets a UI say what happened instead of reporting an empty result.

    Recoverable — call RetryablePromiseState.refetch.

    hasSettled: boolean

    Whether a fetch has completed since the last supersession — resolved or rejected.

    Read this rather than inferring "finished" from !isLoading. isLoading is false both before the first fetch starts and for the render between a refetch and the effect that restarts it, so a caller deriving state from !isLoading alone paints a settled-looking state during a fetch that has not run yet — most visibly a flash of the error state on the very click meant to clear it.

    isLoading: boolean

    Whether a fetch is in flight.

    refetch: () => void

    Clears any error and re-runs the fetch. A no-op when there is no fetch to run, so it never presents itself as a recovery that cannot happen.