Skip to content

Commit 7962d4e

Browse files
committed
feat: fixed infinite refetchs issue
1 parent 112af9f commit 7962d4e

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/components/Hero.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
} from "@chakra-ui/react";
1212
import { ArrowForwardIcon } from "@chakra-ui/icons";
1313
import Image from "next/image";
14+
import NextLink from "next/link";
1415

1516
const Hero = () => {
1617
return (
@@ -43,6 +44,7 @@ const Hero = () => {
4344
</Text>
4445

4546
<Link
47+
as={NextLink}
4648
href={"/getting-started"}
4749
alignSelf={{ base: "center", md: "flex-start" }}
4850
>

src/contexts/AppContextProvider.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,17 @@ export function AppContextProvider({ children }: IProps) {
2323
const [completedQuizzesSlugs, setCompletedQuizzesSlugs] = useState<string[]>(
2424
[],
2525
);
26+
const [sessionDataUser, setSessionDataUser] = useState<any>(null);
2627

2728
const { data: sessionData } = useSession();
2829

30+
useEffect(() => {
31+
if (sessionData?.user && sessionData.user !== sessionDataUser) {
32+
setSessionDataUser(sessionData.user);
33+
}
34+
// eslint-disable-next-line react-hooks/exhaustive-deps
35+
}, [sessionData]);
36+
2937
// Requests
3038
// - All
3139
const {
@@ -36,7 +44,8 @@ export function AppContextProvider({ children }: IProps) {
3644
undefined, // no input
3745
{
3846
// Disable request if no session data
39-
enabled: sessionData?.user !== undefined,
47+
enabled: !!sessionDataUser,
48+
refetchOnWindowFocus: false,
4049
},
4150
);
4251

@@ -73,13 +82,13 @@ export function AppContextProvider({ children }: IProps) {
7382
if (projects && completedQuizzesSlugs.length !== 0) {
7483
const projectsWithCompleteStatus = projects.map((lesson) => {
7584
const completed = completedQuizzesSlugs.includes(lesson.slug);
76-
console.log({ completed });
7785
return { ...lesson, completed };
7886
});
7987

8088
setProjects(projectsWithCompleteStatus);
8189
}
82-
}, [completedQuizzesSlugs, projects]);
90+
// eslint-disable-next-line react-hooks/exhaustive-deps
91+
}, [completedQuizzesSlugs]);
8392

8493
return (
8594
<AppContext.Provider

0 commit comments

Comments
 (0)