Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "hooks/useFetch"

Index

Type aliases

Functions

Type aliases

Action

Action<R>: { type: "FETCH_INIT" } | { payload: string; type: "FETCH_FAILED" } | { type: "FETCH_CANCELED" } | { payload: R; type: "FETCH_SUCCESS" }

Type parameters

  • R: any

Options

Options: { fetchOptions?: RequestInit; lazy?: undefined | false | true }

Type declaration

  • Optional fetchOptions?: RequestInit
  • Optional lazy?: undefined | false | true

State

State<R>: { data: R | null; error: string | null; loading: boolean; status: "pending" | "error" | "success" | "loading" }

Type parameters

  • R: any

Type declaration

  • data: R | null
  • error: string | null
  • loading: boolean
  • status: "pending" | "error" | "success" | "loading"

Functions

Const reducer

  • reducer(state: { data: R | null; error: string | null; loading: boolean; status: "pending" | "error" | "success" | "loading" }, action: { type: "FETCH_INIT" } | { payload: string; type: "FETCH_FAILED" } | { type: "FETCH_CANCELED" } | { payload: R; type: "FETCH_SUCCESS" }): { data: null; error: null; loading: true; status: "loading" } | { data: null; error: string; loading: false; status: "error" } | { data: null; error: null; loading: false; status: "pending" } | { data: any; error: null; loading: false; status: "success" }
  • Parameters

    • state: { data: R | null; error: string | null; loading: boolean; status: "pending" | "error" | "success" | "loading" }
      • data: R | null
      • error: string | null
      • loading: boolean
      • status: "pending" | "error" | "success" | "loading"
    • action: { type: "FETCH_INIT" } | { payload: string; type: "FETCH_FAILED" } | { type: "FETCH_CANCELED" } | { payload: R; type: "FETCH_SUCCESS" }

    Returns { data: null; error: null; loading: true; status: "loading" } | { data: null; error: string; loading: false; status: "error" } | { data: null; error: null; loading: false; status: "pending" } | { data: any; error: null; loading: false; status: "success" }

useFetch

  • useFetch<R>(endpoint: string, options?: Options): [{ data: R | null; error: string | null; loading: boolean; status: "pending" | "error" | "success" | "loading" }, (value: A) => void]
  • Type parameters

    • R: any

    Parameters

    • endpoint: string
    • Default value options: Options = { lazy: false }

    Returns [{ data: R | null; error: string | null; loading: boolean; status: "pending" | "error" | "success" | "loading" }, (value: A) => void]

Const wait

  • wait(ms: number): Promise<unknown>

Generated using TypeDoc