Question
import React, { useState, useEffect } from react; import axios from axios; import { useParams, Link } from react-router-dom; import api from ../../service/api; import './AssignmentPage.css'
import React, { useState, useEffect } from "react"; import axios from "axios"; import { useParams, Link } from "react-router-dom"; import api from "../../service/api"; import './AssignmentPage.css'
const AddQuestion = ({history}) => { let { id } = useParams() console.log('this is in the addQuiz '+id)
const [assignment, setAssignment] = useState({ title:'' });
const [questions, setQuestions] = useState({
quizes:[{
question : '', correct_answer: '', incorrect_answers:[]
}]
});
useEffect(() => { loadQuestions(id); }, []);
const loadQuestions = async ( id ) => { const result = await api.get(`/assignments/${id}`); setQuestions(result.data); }; const {quizes: [{question, correct_answer}]} = questions const onInputChange = e => {
setQuestions({...questions, [e.target.name]: e.target.value }); };
const addQuestion = async (id) => { await api.post(`/assignments/addquestion/${id}`); loadQuestions(); }; const onSubmit = async e => { e.preventDefault(); await api.post(`/assignments/addquestion/${id}`, questions); history.push("/dashboard"); };
return (
# | title | {console.log(id)} {/*Action | */}||
---|---|---|---|---|
{index} | {question.question} | {question.correct_answer} | {question.incorrect_answer} | {/* getAssignmentById(assignment._id)} > View */} {/* Edit */} {/* deleteAssignment(assignment._id)} > Delete */} {/* |
export default AddQuestion;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started