Interface FetchResult<T>

interface FetchResult<T> {
    data: undefined | T;
    loading: boolean;
    ok: boolean;
    status: undefined | number;
}

Type Parameters

  • T = FetchResultData

    Type of the returned result. Can be overwritten. This is useful when defining a custom shape for JSON objects or simply telling TypeScript which return type to use. You don't have to set this type manually. It is just for convenience when using TypeScript, so you don't have to make any type assertions on the output.

Properties

Properties

data: undefined | T

The response to the fetch request. Is undefined if fetch was unsuccessful.

loading: boolean

Indicates if the fetch is still ongoing (i.e. has not finished). Wait for this to be true before reading other fields. Is useful to display a spinner while waiting for results.

ok: boolean

Indicates whether the response was successful (status in the range 200-299) or not.

status: undefined | number

The HTTP status code. Is undefined before first fetch has completed.