Skip to content

Commit

Permalink
refactor quiz page to use Suspense for loading state and improve depe…
Browse files Browse the repository at this point in the history
…ndency management
  • Loading branch information
raspberri05 committed Feb 16, 2025
1 parent 961bfe4 commit b31cc7b
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/app/quiz/page.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"use client";

import Loading from "@/components/loading";
import { useEffect, useState } from "react";
import { useEffect, useState, Suspense } from "react";
import { useSearchParams } from "next/navigation";
import { Question } from "@/types";
import QuizDisplay from "@/components/quiz-display";

export default function Page() {
function QuizContent() {
const searchParams = useSearchParams();
const username = searchParams.get("username");
const period = searchParams.get("period");
Expand All @@ -31,12 +31,20 @@ export default function Page() {
setQuestions(data.questions);
}
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}, [username, period]);

return (
<div>
{loading && <Loading />}
{!loading && <QuizDisplay questions={questions} />}
</div>
);
}

export default function Page() {
return (
<Suspense fallback={<Loading />}>
<QuizContent />
</Suspense>
);
}

0 comments on commit b31cc7b

Please sign in to comment.