Skip to content

Commit

Permalink
ava#355: dependencies with undefined value will not do http request
Browse files Browse the repository at this point in the history
  • Loading branch information
Md. Fasihul Kabir committed Nov 9, 2021
1 parent 3777735 commit 307b5ee
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/useFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
} from './types'
import useFetchArgs from './useFetchArgs'
import doFetchArgs from './doFetchArgs'
import { invariant, tryGetData, toResponseObject, useDeepCallback, isFunction, sleep, makeError } from './utils'
import { invariant, tryGetData, toResponseObject, useDeepCallback, isFunction, sleep, makeError, isEmpty } from './utils'
import useCache from './useCache'

const { CACHE_FIRST } = CachePolicies
Expand Down Expand Up @@ -229,11 +229,15 @@ function useFetch<TData = any>(...args: UseFetchArgs): UseFetch<TData> {
// onMount/onUpdate
useEffect((): any => {
mounted.current = true
if (Array.isArray(dependencies)) {
const methodName = requestInit.method || HTTPMethod.GET
const methodLower = methodName.toLowerCase() as keyof ReqMethods<TData>
const req = request[methodLower] as NoArgs
req()
if (
Array.isArray(dependencies) &&
(dependencies.length === 0 ||
dependencies.filter((d) => !isEmpty(d)).length > 0)
) {
const methodName = requestInit.method || HTTPMethod.GET;
const methodLower = methodName.toLowerCase() as keyof ReqMethods<TData>;
const req = request[methodLower] as NoArgs;
req();
}
return () => mounted.current = false
}, dependencies)
Expand Down

0 comments on commit 307b5ee

Please sign in to comment.