Skip to main content

TypeAlias.ApiResult

type ApiResult<T, Extra>: readonly [T, null, Extra] | readonly [null, Error, Extra];

A tuple representing the result of an API call to the Keyban servers.

Since all Keyban hooks use the React Suspense API, there are only two possible states for the tuple: success and error.

The tuple contains the following data:

  • On success:
  • The data result of the API call (of type T).
  • null for the error.
  • An optional extra object (of type Extra) allowing for additional interactions.
  • On error:
  • null for the data.
  • An Error object representing the error.
  • An optional extra object (of type Extra) allowing for additional interactions.

Type Parameters

Type ParameterDefault typeDescription
T-The type of the data returned on success.
ExtraundefinedThe type of the optional extra object for additional interactions.

Remarks

The ApiResult type is designed to simplify handling asynchronous API responses in Keyban hooks. It adheres to the pattern [data, error, extra], where:

  • data: The result of the API call if successful, or null if there was an error.
  • error: null if the call was successful, or an Error object if there was an error.
  • extra: An optional object providing additional information or methods, defaulting to undefined if not used.

Example Usage:

const [data, error, extra] = useKeybanSomeHook();
if (error) {
// Handle the error
console.error(error);
} else {
// Use the data
console.log(data);
// Optionally use extra interactions
extra?.someMethod();
}