From a0e2979bbb8539b19a8cedcd395612e1700388f9 Mon Sep 17 00:00:00 2001
From: "Md. Fasihul Kabir" <aboutrafi@gmail.com>
Date: Wed, 10 Nov 2021 01:07:27 +0600
Subject: [PATCH] #355: dependencies with undefined value will not do http
 request

---
 src/useFetch.ts | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/useFetch.ts b/src/useFetch.ts
index f51f921..59bf5e2 100644
--- a/src/useFetch.ts
+++ b/src/useFetch.ts
@@ -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
@@ -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)