diff --git a/README.md b/README.md index 5a17ddc73..32fae0aa2 100644 --- a/README.md +++ b/README.md @@ -113,7 +113,7 @@ const { data, error, isValidating, mutate } = useSWR(key, fetcher, options) #### Options - `suspense = false`: enable React Suspense mode [(details)](#suspense-mode) -- `fetcher = window.fetch`: the default fetcher function +- `fetcher`: the function to retrieve the remote data source - `initialData`: initial data to be returned (note: This is per-hook) - `revalidateOnMount`: enable or disable automatic revalidation when component is mounted (by default revalidation occurs on mount when initialData is not set, use this flag to force behavior) - `revalidateOnFocus = true`: auto revalidate when window gets focused diff --git a/src/types.ts b/src/types.ts index d73fd1c39..31c5fdc89 100644 --- a/src/types.ts +++ b/src/types.ts @@ -18,7 +18,7 @@ export interface Configuration< shouldRetryOnError: boolean suspense?: boolean initialData?: Data - fetcher: Fn + fetcher?: Fn cache: Cache middlewares?: Middleware[] diff --git a/src/utils/config.ts b/src/utils/config.ts index 1a30c5445..4f4e44ee7 100644 --- a/src/utils/config.ts +++ b/src/utils/config.ts @@ -6,7 +6,6 @@ import { slowConnection } from './env' import { Configuration, RevalidatorOptions, Revalidator } from '../types' import { UNDEFINED } from './helper' -const fetcher = (url: string) => fetch(url).then(res => res.json()) const noop = () => {} // error retry @@ -56,7 +55,6 @@ const defaultConfig: Configuration = { loadingTimeout: slowConnection ? 5000 : 3000, // providers - fetcher, compare: dequal, isPaused: () => false, cache: wrapCache(new Map()), diff --git a/test/use-swr-integration.test.tsx b/test/use-swr-integration.test.tsx index 585980d4e..c4d318610 100644 --- a/test/use-swr-integration.test.tsx +++ b/test/use-swr-integration.test.tsx @@ -357,27 +357,4 @@ describe('useSWR', () => { expect(fetcher).toBeCalled() await screen.findByText('hello, SWR') }) - - it('should use fetch api as default fetcher', async () => { - const users = [{ name: 'bob' }, { name: 'sue' }] - global['fetch'] = () => Promise.resolve() - const mockFetch = body => - Promise.resolve({ json: () => Promise.resolve(body) } as any) - const fn = jest - .spyOn(window, 'fetch') - .mockImplementation(() => mockFetch(users)) - - function Users() { - const { data } = useSWR('http://localhost:3000/api/users') - - return