UNPKG

@gluons/react-native-fetch-with-timeout

Version:

Fetch with timeout for React Native.

41 lines (40 loc) 1.1 kB
/// <reference types="react-native" /> /** * Abort handler. * Prevent error thrown when `fetch` aborted. * * @param err Error * @returns Empty JSON response (`{}`) */ export declare const AbortHandler: (err: Error) => Response; /** * Options of `fetchWithTimeout`. */ export interface FetchWithTimeoutOptions { /** * Timeout (ms) (`false` for disabling timeout. Use plain `fetch`.) * * @default false */ timeout?: number | false; /** * Abort controller * * @default new AbortController() */ abortController?: AbortController; /** * Handler when `fetch` aborted. * * @default AbortHandler */ abortHandler?: typeof AbortHandler; } /** * `fetch` with timeout support. * * @param {RequestInfo} input Request info * @param {RequestInit} init Request options * @param {FetchWithTimeoutOptions} timeout `fetchWithTimeout`'s options */ export default function fetchWithTimeout(input: RequestInfo, init?: RequestInit, options?: FetchWithTimeoutOptions): Promise<Response>;