useLoadingSlowFn

This Hook is available since v1.4.0.

A React Hook like useAsyncFn for easily handling loading slow state.

Demo

Source
Loading:
false
LoadingSlow:
false
Value:
click to fetch

Usage

See API for more details.

Source

Click links below to view source on GitHub.

API

const { loadingSlow, ...useAsyncFnReturns } = useLoadingSlowFn(fn, options):

Fn

A function that returns a promise.

Options

See UseAsyncFnOptions for more details.

export interface UseLoadingSlowFnOptions<T extends AnyFunc, D = Awaited<ReturnType<T>>, E = any>
  extends UseAsyncFnOptions<T, D, E> {
  /**
   * The timeout duration in milliseconds to determine if the loading is slow.
   *
   * @defaultValue 0 ms
   */
  loadingTimeout?: number
  /**
   * A callback to be called when the loading is slow.
   *
   * @defaultValue undefined
   */
  onLoadingSlow?: () => void
}

Returns

See UseAsyncFnReturns for more details.

export interface UseLoadingSlowFnReturns<T extends AnyFunc, D = Awaited<ReturnType<T>>, E = any>
  extends UseAsyncFnReturns<T, D, E> {
  /**
   * Whether the loading is slow.
   */
  loadingSlow: boolean
}