From 73f0995c8d7855fc1b4ec16f7392c17fdb3bdae8 Mon Sep 17 00:00:00 2001
From: Anishali2 <ansihali1221@gmail.com>
Date: Fri, 19 Apr 2024 04:56:35 +0500
Subject: [PATCH] [Bug]: Re-rendering issue in user profile page

---
 apps/web/app/hooks/useInfinityFetch.ts | 16 ++++++++++------
 apps/web/next.config.js                |  1 +
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/apps/web/app/hooks/useInfinityFetch.ts b/apps/web/app/hooks/useInfinityFetch.ts
index 99bd60f7b..506115430 100644
--- a/apps/web/app/hooks/useInfinityFetch.ts
+++ b/apps/web/app/hooks/useInfinityFetch.ts
@@ -15,17 +15,21 @@ export const useInfinityScrolling = <T>(arr: T[], lim?: number) => {
 
 	const getSomeTasks = React.useCallback(
 		(offset: number) => {
-			setData(() => {
-				const newData = getPartData({ arr, limit, offset });
-				return newData;
-			});
+			if (arr.length > 0) {
+				setData(() => {
+					const newData = getPartData({ arr, limit, offset });
+					return newData;
+				});
+			}
 		},
 		[arr, limit]
 	);
 
 	const nextOffset = React.useCallback(() => {
-		setOffset((prev) => prev + 1);
-	}, []);
+		if (arr.length > 0) {
+			setOffset((prev) => prev + 1);
+		}
+	}, [arr.length]);
 
 	React.useEffect(() => {
 		getSomeTasks(offset);
diff --git a/apps/web/next.config.js b/apps/web/next.config.js
index b9b820640..6bc0ba0d5 100644
--- a/apps/web/next.config.js
+++ b/apps/web/next.config.js
@@ -74,6 +74,7 @@ const nextConfig = {
 		domains: [
 			'dummyimage.com',
 			'res.cloudinary.com',
+			'gauzy.sfo2.digitaloceanspaces.com',
 			'localhost',
 			'127.0.0.1',
 			'cdn-icons-png.flaticon.com', // Remove this domain once the Backend Icons list is added