import React, { useState, useEffect } from 'react' import { Link, Redirect } from 'react-router-dom'; import Timer from 'react-compound-timer'; // 타이머쓰기위해 import import logo from './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)) }},[]) //그걸 로컬에 저장 //foreach 쓰기 let finalQnA = localQnA.map((x, index) => { //delete x.A //A 삭제 return { ...x, N: index + 1 } //N 추가 }) 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 ( <>