Skip to content

Commit a0e2979

Browse files
committed
#355: dependencies with undefined value will not do http request
1 parent 031b2ee commit a0e2979

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/useFetch.ts

+10-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
} from './types'
2020
import useFetchArgs from './useFetchArgs'
2121
import doFetchArgs from './doFetchArgs'
22-
import { invariant, tryGetData, toResponseObject, useDeepCallback, isFunction, sleep, makeError } from './utils'
22+
import { invariant, tryGetData, toResponseObject, useDeepCallback, isFunction, sleep, makeError, isEmpty } from './utils'
2323
import useCache from './useCache'
2424

2525
const { CACHE_FIRST } = CachePolicies
@@ -229,11 +229,15 @@ function useFetch<TData = any>(...args: UseFetchArgs): UseFetch<TData> {
229229
// onMount/onUpdate
230230
useEffect((): any => {
231231
mounted.current = true
232-
if (Array.isArray(dependencies)) {
233-
const methodName = requestInit.method || HTTPMethod.GET
234-
const methodLower = methodName.toLowerCase() as keyof ReqMethods<TData>
235-
const req = request[methodLower] as NoArgs
236-
req()
232+
if (
233+
Array.isArray(dependencies) &&
234+
(dependencies.length === 0 ||
235+
dependencies.filter((d) => !isEmpty(d)).length > 0)
236+
) {
237+
const methodName = requestInit.method || HTTPMethod.GET;
238+
const methodLower = methodName.toLowerCase() as keyof ReqMethods<TData>;
239+
const req = request[methodLower] as NoArgs;
240+
req();
237241
}
238242
return () => mounted.current = false
239243
}, dependencies)

0 commit comments

Comments
 (0)