Options
All
  • Public
  • Public/Protected
  • All
Menu

react-js-async-hooks

Index

Type aliases

ErrorHandlerCallback

ErrorHandlerCallback: (e: Error) => void

Type declaration

    • (e: Error): void
    • Parameters

      • e: Error

      Returns void

OnErrorEvent

OnErrorEvent<E>: (e: E) => void | undefined

Type parameters

Type declaration

    • (e: E): void | undefined
    • Parameters

      • e: E

      Returns void | undefined

OnSuccessEvent

OnSuccessEvent<R>: (result: R | void | undefined) => void

Type parameters

  • R

Type declaration

    • (result: R | void | undefined): void
    • Parameters

      • result: R | void | undefined

      Returns void

UnsafeAsyncCallback

UnsafeAsyncCallback<T>: () => Promise<T | void | undefined> | undefined | void

Type parameters

  • T

Type declaration

    • (): Promise<T | void | undefined> | undefined | void
    • Returns Promise<T | void | undefined> | undefined | void

Variables

ErrorHandlerContext

ErrorHandlerContext: Context<undefined | ErrorHandlerCallback> = ...

ErrorHandlerProvider

ErrorHandlerProvider: React.FC<ErrorHandlerProviderProps> = ...

Functions

Const makeCancelable

  • makeCancelable<T>(promise: Promise<T>): [Promise<T>, () => void]
  • The following function was based on @istarkov code

    Type parameters

    • T

    Parameters

    • promise: Promise<T>

    Returns [Promise<T>, () => void]

Const useAsyncCallback

  • useAsyncCallback<R, P>(asyncCallback: (...params: P) => Promise<undefined | void | R>, deps: DependencyList): (...params: P) => Promise<undefined | void | R>
  • This hook allows a safe execution of an async callback within an imperative funcion.

    Type parameters

    • R

    • P: unknown[]

    Parameters

    • asyncCallback: (...params: P) => Promise<undefined | void | R>
        • (...params: P): Promise<undefined | void | R>
        • Parameters

          • Rest ...params: P

          Returns Promise<undefined | void | R>

    • deps: DependencyList

    Returns (...params: P) => Promise<undefined | void | R>

      • (...params: P): Promise<undefined | void | R>
      • Parameters

        • Rest ...params: P

        Returns Promise<undefined | void | R>

Const useAsyncEffect

  • This hook provides a way to call any async function without the need to handle race conditions or memory leak problems.

    The state change due to errors response must be done within onError param. Any other successful result can safely change states withing onSuccess.

    It is possible to add an error handler context in a component tree using the ErrorHandlerProvider. The onError param has precedence over the error handler in the context.

    Type parameters

    Parameters

    Returns AsyncCallbackStatus

Const useErrorHandlerCallback

Generated using TypeDoc