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() { const [question, setQuestion] = useState({ ...localQnA[0] }) const [selected, setSelected] = useState("") //선택한 답을 보여줄 것 const [timeout, settimeout] = useState(false) //for each 사용하기 let Solutions = [] //빈 배열 console.log(localQnA) localQnA.map((x) => { //A만 꺼내서 q에 추가 // Answers.push(0) return Solutions.push(x.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 ( <>