From 444da2b1eaa64a3a7a263c4a7ee9b3e9e1973e2c Mon Sep 17 00:00:00 2001
From: Noah Hernandez <63211322+oahnh@users.noreply.github.com>
Date: Sun, 26 May 2024 16:18:39 -0700
Subject: [PATCH 1/2] fix: move window into useEffect
---
src/app/testing/page.tsx | 16 ----------------
src/components/userComponents/Footer/Footer.tsx | 10 ++++++----
.../WindowWidthContext/WindowWidthContext.tsx | 10 +++++++---
3 files changed, 13 insertions(+), 23 deletions(-)
delete mode 100644 src/app/testing/page.tsx
diff --git a/src/app/testing/page.tsx b/src/app/testing/page.tsx
deleted file mode 100644
index 2e66860c..00000000
--- a/src/app/testing/page.tsx
+++ /dev/null
@@ -1,16 +0,0 @@
-// @ts-nocheck
-'use client';
-
-/* eslint-disable */
-
-import React from 'react';
-import ImageScroller from '@/components/userComponents/ImageScroller/ImageScroller';
-import Carousel from '@/components/userComponents/ImageScroller/ImageScroller';
-
-export default function Test() {
- return (
-
-
-
- );
-}
diff --git a/src/components/userComponents/Footer/Footer.tsx b/src/components/userComponents/Footer/Footer.tsx
index 9bc7cc8e..fbef46d0 100644
--- a/src/components/userComponents/Footer/Footer.tsx
+++ b/src/components/userComponents/Footer/Footer.tsx
@@ -344,12 +344,14 @@ export default function Footer() {
const [inputValueEmail, setEmailValue] = useState('');
const [showError, setShowError] = useState(false);
const [errorMsg, setErrorMsg] = useState('');
-
- const subbed = () =>
- Boolean(JSON.parse(window.sessionStorage.getItem('subscribed') || 'false'));
- const [subscribed, setSubscribed] = useState(subbed);
+ const [subscribed, setSubscribed] = useState(false);
useEffect(() => {
+ const subbed = () =>
+ Boolean(
+ JSON.parse(window.sessionStorage.getItem('subscribed') || 'false'),
+ );
+ setSubscribed(subbed);
window.sessionStorage.setItem('subscribed', subscribed.toString());
}, [subscribed]);
diff --git a/src/context/WindowWidthContext/WindowWidthContext.tsx b/src/context/WindowWidthContext/WindowWidthContext.tsx
index a9a4b507..f8330ce6 100644
--- a/src/context/WindowWidthContext/WindowWidthContext.tsx
+++ b/src/context/WindowWidthContext/WindowWidthContext.tsx
@@ -6,6 +6,7 @@ import React, {
useEffect,
useContext,
useMemo,
+ useCallback,
} from 'react';
interface WindowWidthContextProps {
@@ -29,15 +30,18 @@ export function WindowWidthProvider({
}: {
children: React.ReactNode;
}) {
- const [isWeb, setIsWeb] = useState(window.innerWidth >= 1024);
+ const [isWeb, setIsWeb] = useState(false);
+ const handleResize = useCallback(() => {
+ setIsWeb(window.innerWidth >= 1024);
+ }, []);
useEffect(() => {
- const handleResize = () => setIsWeb(window.innerWidth >= 1024);
+ handleResize();
window.addEventListener('resize', handleResize);
return () => {
window.removeEventListener('resize', handleResize);
};
- }, []);
+ }, [handleResize]);
const windowWidthValue = useMemo(() => ({ isWeb }), [isWeb]);
From 4f2d01ba24de8fd1bb26b2628c300dea0d83db35 Mon Sep 17 00:00:00 2001
From: Noah Hernandez <63211322+oahnh@users.noreply.github.com>
Date: Sun, 26 May 2024 16:19:03 -0700
Subject: [PATCH 2/2] fix: remove news state dependency from useEffect
---
src/app/news/page.tsx | 2 +-
.../HomePageComponents/HomeNewsFeed/HomeNewsFeed.tsx | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/app/news/page.tsx b/src/app/news/page.tsx
index bc438877..a7e116be 100644
--- a/src/app/news/page.tsx
+++ b/src/app/news/page.tsx
@@ -24,7 +24,7 @@ export default function App() {
setNews(fetchedNews);
};
getNews();
- }, [news]);
+ }, []);
return (
diff --git a/src/components/userComponents/HomePageComponents/HomeNewsFeed/HomeNewsFeed.tsx b/src/components/userComponents/HomePageComponents/HomeNewsFeed/HomeNewsFeed.tsx
index 863392d9..70ffb0f5 100644
--- a/src/components/userComponents/HomePageComponents/HomeNewsFeed/HomeNewsFeed.tsx
+++ b/src/components/userComponents/HomePageComponents/HomeNewsFeed/HomeNewsFeed.tsx
@@ -23,12 +23,12 @@ function HomeNewsFeed() {
setNews(topThreeNews);
};
getNews();
- }, [news]);
+ }, []);
return (
{isWebDevice && (