Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 (

{console.log('this is the name of the question ** '+ questions)}
onSubmit(e)}>
onInputChange(e)} />
onInputChange(e)} />
{/*
onInputChange(e)} />
*/} {/*
onInputChange(e)} />
*/} {/* < Link class="btn btn-danger" onClick={() => deleteAssignment(assignment._id)} > Delete */}
{console.log(id)} {/* */} {/* {questions.map((question, index) => ( ))} */}
# titleAction
{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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions