Skip to content

Commit

Permalink
refactor: add workaround for useFetch
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanhofer committed Sep 15, 2022
1 parent 83c39c3 commit 7f42f5b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/context/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import { Headers } from 'headers-polyfill'
import { MockedRequest } from '../utils/request/MockedRequest'

const useFetch: (input: RequestInfo, init?: RequestInit) => Promise<Response> =
isNodeProcess() ? require('node-fetch') : window.fetch
isNodeProcess()
? (input, init) =>
import('node-fetch').then(({ default: nodeFetch }) =>
(nodeFetch as unknown as typeof window.fetch)(input, init),
)
: window.fetch

export const augmentRequestInit = (requestInit: RequestInit): RequestInit => {
const headers = new Headers(requestInit.headers)
Expand Down

0 comments on commit 7f42f5b

Please sign in to comment.