Skip to content

Commit

Permalink
routerをrefreshして新しいデータをとる
Browse files Browse the repository at this point in the history
  • Loading branch information
k35o committed Sep 29, 2024
1 parent c6c0e2d commit 7868646
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/app/quizzes/_components/question/question.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { QuizProgress } from '../quiz-progress';
import { Answer } from '../answer';
import { Feedback } from '../feedback';
import { checkAnswer } from '../../_utils/check-answer';
import { useRouter } from 'next/navigation';

type QuestionProps = FC<{
quizzes: Quiz[];
Expand All @@ -21,6 +22,8 @@ export const Question: QuestionProps = ({ quizzes }) => {
const [score, setScore] = useState(0);
const currentQuiz = quizzes[count];

const router = useRouter();

if (currentQuiz === undefined) {
throw new Error('クイズがありません');
}
Expand Down Expand Up @@ -48,10 +51,11 @@ export const Question: QuestionProps = ({ quizzes }) => {
}, [count, quizzes.length]);

const handleReset = useCallback(() => {
router.refresh();
setCount(0);
setStatus('none');
setAnswer('');
}, []);
}, [router]);

if (status === 'complete') {
return (
Expand Down

0 comments on commit 7868646

Please sign in to comment.