Skip to main content

FetchHelper()

고차 함수로 fetch를 확장하거나, interceptor, baseUrl, headers 을 옵션으로 넣어 사용할 수 있습니다.

Signature

fetchHelper: (defaultOptions?: FetchHelperDefaultOptions) => (input: string | URL | Request, init?: RequestInit | undefined) => Promise<Response>

Parameters

Parameter

Type

Description

defaultOptions

FetchHelperDefaultOptions

(Optional) fetchHelper 함수의 옵션입니다.

Returns

(input: string | URL | Request, init?: RequestInit | undefined) => Promise<Response>

Example

export const fetchHelperInterceptors: FetchHelper = (args) =>
fetchHelper({
...args,
interceptors: {
request: requestInterceptor,
response: responseInterceptor,
},
})


import { fetchHelperInterceptors } from './fetch-interceptors'

export const fetchExtended = fetchHelperInterceptors({
baseUrl: https://jsonplaceholder.typicode.com
})

export default fetchExtended

fetchExtended('/todos/1')