"use client"; import { useState } from "react"; import { useBoolean, useInterval, useUpdateEffect } from "react-use"; import { RxLapTimer } from "react-icons/rx"; import { useQuizz } from "./hooks/useQuizz"; import { PromptType } from "@/utils/type"; import { Card } from "./card"; import { Button } from "../button/button"; import Link from "next/link"; export const QuizzContent = () => { const { loading, prompts, question, onScore, result, score } = useQuizz(); const [counter, setCounter] = useState(10); const [isRunning, toggleIsRunning] = useBoolean(true); useUpdateEffect(() => { if (!counter) { (async () => { await onScore(); return; })(); } }, [counter]); useInterval( () => { if (counter > 0) { setCounter(counter - 1); } }, isRunning ? 1000 : null ); const handleScore = async (id: string) => { toggleIsRunning(false); await onScore(id); }; useUpdateEffect(() => { if (typeof score !== "number") return; toggleIsRunning(true); const delay = score > 10 ? 5 : score > 5 ? 8 : 10; setCounter(delay); }, [question]); return (
“ {question} ”
)}Guess which image is related to the prompt above