Logos DX
    Preparing search index...

    Function useAsync

    • Generic async hook — wraps any async function with loading/failure/data state. Auto-executes on mount and when deps change.

      If the function returns a FetchResponse (from FetchEngine methods), the .data property is automatically unwrapped, and an ok: false response sets failure: { kind: 'http', response } instead of being treated as success. useAsync wraps an arbitrary function, so it can't promise a FetchError the way useQuery does — a rejection sets failure: { kind: 'rejected', error } with the thrown value as-is.

      const { data, loading, failure } = useAsync(
          () => myApi.getUsers(page),
          [page],
      );
      

      Type Parameters

      • T = unknown
      • E extends Record<string, any> = Record<string, any>

      Parameters

      • fn: () => Promise<unknown>

        Async function to execute

      • deps: DependencyList

        React dependency list — re-executes when these change

      • Optionaloptions: AsyncOptions<E>

        skip, pollInterval, invalidateOn

      • Optionalobserver: ObserverEngine<E>

        Optional ObserverEngine for invalidateOn support

      Returns AsyncResult<T>