Commit 12d64edc authored by Jiwon Yoon's avatar Jiwon Yoon
Browse files

update

parent bf12e0b5
......@@ -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(<AdminQuiz quizNum={e.target.id} fn={handleClickSave} data={dbRef.current[e.target.id]} />)
// console.log(dbRef.current, indexRef.current)
if(dbRef.current[e.target.id-1]){
setresult(<AdminQuiz quizNum={e.target.id} fn={handleClickSave} data={dbRef.current[e.target.id-1]} />)
}
else{
dbRef.current[e.target.id-1] = {'Q':'x', 'Choose':[0,0,0,0], 'A':'x'}
setresult(<AdminQuiz quizNum={e.target.id} fn={handleClickSave} data={dbRef.current[e.target.id-1]} />)
}
}
function handleClickAddQuiz() {
......
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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment