Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
students
online-quiz-react
Commits
12d64edc
Commit
12d64edc
authored
Aug 17, 2020
by
Jiwon Yoon
Browse files
update
parent
bf12e0b5
Changes
2
Show whitespace changes
Inline
Side-by-side
src/Admin.js
View file @
12d64edc
...
...
@@ -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
()
{
...
...
src/AdminQuiz.js
View file @
12d64edc
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment