1- import { FC , useState } from "react" ;
1+ import { type FC , useState } from "react" ;
22import { useForm , FieldValues } from "react-hook-form" ;
33import { Question } from "./types" ;
44import Image from "next/image" ;
@@ -22,7 +22,7 @@ const QuizForm: FC<Props> = ({
2222 totalQuestions,
2323 link,
2424} ) => {
25- const { register, handleSubmit, reset } = useForm ( ) ;
25+ const { register, handleSubmit, reset, watch } = useForm ( ) ;
2626 const [ showCorrectAnswer , setShowCorrectAnswer ] = useState < boolean > ( false ) ;
2727 const [ lastIndex , setLastIndex ] = useState < number > ( 1 ) ;
2828 const [ canGoBack , setCanGoBack ] = useState < boolean > ( false ) ;
@@ -55,6 +55,7 @@ const QuizForm: FC<Props> = ({
5555
5656 if ( isLoading ) return < p > Loading...</ p > ;
5757 const { question, options, images } = questionSet ! ;
58+ const watchInput = watch ( `options.${ currentQuestionIndex } ` ) ;
5859
5960 const noOfAnswers = options . filter ( ( el ) => el . isAnswer === true ) . length ;
6061 return (
@@ -144,7 +145,7 @@ const QuizForm: FC<Props> = ({
144145 </ svg >
145146 </ button >
146147 </ div >
147- < p className = "text-white px-12 pt-10 pb-5 select-none" > { question } </ p >
148+ < p className = "text-white md: px-12 pt-10 pb-5 select-none" > { question } </ p >
148149 { images . length !== 0 && (
149150 < ul className = "flex flex-row justify-center gap-2 mt-5 mb-8 select-none md:px-12 px-0" >
150151 { images . map ( ( image ) => (
@@ -213,6 +214,10 @@ const QuizForm: FC<Props> = ({
213214 disabled = { currentQuestionIndex < lastIndex }
214215 onClick = { ( ) => {
215216 setShowCorrectAnswer ( false ) ;
217+ setSavedAnswers ( ( prev ) => ( {
218+ ...prev ,
219+ [ currentQuestionIndex ] : watchInput ,
220+ } ) ) ;
216221 if ( currentQuestionIndex === totalQuestions ) {
217222 handleNextQuestion ( 1 ) ;
218223 setLastIndex ( 1 ) ;
0 commit comments