import React, { useState, useEffect } from 'react' import { Link, Redirect } from 'react-router-dom'; import Timer from 'react-compound-timer'; // 타이머쓰기위해 import import logo from './img/img_question.png' let localQnA = JSON.parse(localStorage.getItem('QnA')) let Answers = [] function Quiz() { let Time = 0 if (JSON.parse(localStorage.getItem("Set")) === null) { Time = 30010 } else { Time = Number(JSON.parse(localStorage.getItem("Set"))[0].Time) } //수정. 추가. 새로 설정한 시간으로 설정 const [question, setQuestion] = useState({ ...localQnA[0] }) const [selected, setSelected] = useState("") //선택한 답을 보여줄 것 const [timeout, settimeout] = useState(false) //for each 사용하기 let Solutions = [] //빈 배열 console.log(localQnA) localQnA.forEach((element) => { Solutions.push(Number(element.A)) }); useEffect(() => { for (let i = 1; i <= Solutions.length; i++) { Answers.push(0) localStorage.setItem('Answers', JSON.stringify(Answers)) localStorage.setItem("Solutions", JSON.stringify(Solutions)) } // eslint-disable-next-line }, []) function handleQuestion() { setQuestion({ ...localQnA[question.N] }) setSelected("") //페이지 넘어가면 selected 초기화 } let handleChange = (ev) => { setSelected(ev.target.value) //selected값 변경 Answers[question.N - 1] = Number(ev.target.id) + 1 localStorage.setItem('Answers', JSON.stringify(Answers)) } return ( <>