diff --git a/db.json b/db.json
index 73ed95d1a..6d964418b 100644
--- a/db.json
+++ b/db.json
@@ -3,38 +3,68 @@
{
"id": 1,
"prompt": "What special prop should always be included for lists of elements?",
- "answers": ["id", "name", "key", "prop"],
- "correctIndex": 2
+ "answers": [
+ "id",
+ "name",
+ "key",
+ "prop"
+ ],
+ "correctIndex": 3
},
{
"id": 2,
"prompt": "A React component is a function that returns ______.",
- "answers": ["HTML", "JSX", "props", "state"],
+ "answers": [
+ "HTML",
+ "JSX",
+ "props",
+ "state"
+ ],
"correctIndex": 1
},
{
"id": 3,
"prompt": "Which event handler will run when a user is finished filling out a form?",
- "answers": ["onSubmit", "onClick", "onChange", "onForm"],
- "correctIndex": 0
+ "answers": [
+ "onSubmit",
+ "onClick",
+ "onChange",
+ "onForm"
+ ],
+ "correctIndex": 2
},
{
"id": 4,
"prompt": "______ is a tool that transpiles JSX into valid JavaScript.",
- "answers": ["React", "Babel", "Webpack", "ES6"],
+ "answers": [
+ "React",
+ "Babel",
+ "Webpack",
+ "ES6"
+ ],
"correctIndex": 1
},
{
"id": 5,
"prompt": "What syntax makes it possible to unpack values from arrays, or properties from objects, into distinct variables?",
- "answers": ["spread", "key-value", "coalescing", "destructuring"],
+ "answers": [
+ "spread",
+ "key-value",
+ "coalescing",
+ "destructuring"
+ ],
"correctIndex": 3
},
{
"id": 6,
"prompt": "Returning different elements from a component depending on the state of your application is known as _____ rendering.",
- "answers": ["voodoo", "conditional", "reactive", "controlled"],
+ "answers": [
+ "voodoo",
+ "conditional",
+ "reactive",
+ "controlled"
+ ],
"correctIndex": 1
}
]
-}
+}
\ No newline at end of file
diff --git a/src/components/App.js b/src/components/App.js
index 4d33c1320..0849d3fa2 100644
--- a/src/components/App.js
+++ b/src/components/App.js
@@ -1,15 +1,55 @@
-import React, { useState } from "react";
+import React, { useState, useEffect } from "react";
import AdminNavBar from "./AdminNavBar";
import QuestionForm from "./QuestionForm";
import QuestionList from "./QuestionList";
function App() {
const [page, setPage] = useState("List");
+ const [questions, setQuestions] = useState([]);
+
+ useEffect(() => {
+ fetch("http://localhost:4000/questions")
+ .then((res) => res.json())
+ .then((questions) => {
+ setQuestions(questions);
+ });
+ }, []);
+
+ const addQuestion = (newQuestion) => {
+ setQuestions([...questions, newQuestion]);
+ };
+
+ const deleteQuestion = (deletedQuestion) => {
+ const updatedQuestions = questions.filter(
+ (question) => question.id !== deletedQuestion.id
+ );
+ setQuestions(updatedQuestions);
+ };
+
+ const updateQuestion = (updatedQuestion) => {
+ const updatedQuestions = questions.map((question) =>
+ question.id === updatedQuestion.id ? updatedQuestion : question
+ );
+ setQuestions(updatedQuestions);
+ };
+
+ let content = page;
+ if (page === "Form") {
+ content =