@polargold/pg-frontend-vue
    Preparing search index...

    Function useApi

    • Wraps an async callback with reactive isLoading/apiData state.

      Error contract (Pattern A of the error-handling policy): if callback throws, the failure is wrapped in an ApiCallError (the original error is preserved on .cause), onError (when provided) is invoked with that ApiCallError, and it is then always rethrown from callApi. A caller that doesn't pass onError still learns about the failure - it just has to await/.catch() callApi itself, the same as it would for any other async function.

      Type Parameters

      • ReturnValue
      • Parameters = void

      Parameters

      Returns {
          apiData: Ref<ReturnValue | undefined, ReturnValue | undefined>;
          callApi: (parameters?: Parameters) => Promise<void>;
          isLoading: Ref<boolean, boolean>;
      }