diff --git a/src/Admin.js b/src/Admin.js index 9814baef342e326a4b7745d59897447016406e06..43b05355d90ff645d47b25c8bf1488ce0777c34b 100644 --- a/src/Admin.js +++ b/src/Admin.js @@ -11,7 +11,6 @@ function Admin() { const indexRef = useRef(0) const dbRef = useRef([]) - useEffect(() => { if (JSON.parse(localStorage.getItem('QnA'))) { dbRef.current=JSON.parse(localStorage.getItem('QnA')) @@ -24,9 +23,15 @@ function Admin() { function handleClickQuiz(e) { indexRef.current = Number(e.target.id) - 1 - console.log(dbRef.current, indexRef.current) - setresult() + // console.log(dbRef.current, indexRef.current) + if(dbRef.current[e.target.id-1]){ + setresult() + } + else{ + dbRef.current[e.target.id-1] = {'Q':'x', 'Choose':[0,0,0,0], 'A':'x'} + setresult() + } } function handleClickAddQuiz() { diff --git a/src/AdminQuiz.js b/src/AdminQuiz.js index 74254d8aed328de7c3cdab5b36d5c24e6d8bd94e..380437e86e9ab34f16d5908e622fdf681bc74025 100644 --- a/src/AdminQuiz.js +++ b/src/AdminQuiz.js @@ -1,4 +1,4 @@ -import React, { useState} from 'react'; +import React, { useState, useEffect } from 'react'; let list = [] let QnAadmin = {} @@ -7,16 +7,17 @@ let savechoose = {} function AdminQuiz(props) { const [question, setQuestion] = useState(props.data.Q) - // setQuestion(props.data.Q) - // question = props.data.Q const [choose, setChoose] = useState(props.data.Choose) - // setChoose(props.data.Choose) - // choose = props.data.Choose const [answer, setAnswer] = useState(props.data.A) - // setAnswer(props.data.A) - // answer = props.data.A const [selectOption, setselectOption] = useState(1) + // props.quizNum가 바뀔때마다 즉, Admin.js에서 퀴즈버튼을 바꿔누를때마다 useEffect가 발생하여 값을 업데이트 시켜줍니다. + useEffect(() => { + setQuestion(props.data.Q) + setChoose(props.data.Choose) + setAnswer(props.data.A) + },[props.quizNum]) + const handleChangeQuestion = (event) => { QnAadmin['Q'] = event.target.value @@ -41,7 +42,7 @@ function AdminQuiz(props) { - + ) setselectOption(selectOption + 1) @@ -79,17 +80,17 @@ function AdminQuiz(props) {
2. 보기 입력하기
-
-
-
- +
+
+
+ +
+
- + {list.map((element) => element)} +
- {list.map((element) => element)} - -