quiz
This commit is contained in:
@ -3,13 +3,16 @@ import { useState } from "react";
|
||||
export const useHandlerFieldTest = ({ questions, indexQuestion }) => {
|
||||
const [userResponses, setUserResponses] = useState([]);
|
||||
const handleChangeCheckbox = (e) => {
|
||||
setUserResponses((prev) =>
|
||||
[...prev.filter((item) => item.question_id !== questions[indexQuestion].id),
|
||||
setUserResponses((prev) => [
|
||||
...prev.filter(
|
||||
(item) => item.question_id !== questions[indexQuestion].id
|
||||
),
|
||||
{
|
||||
question_id: questions[indexQuestion].id,
|
||||
response_body: e.target.value,
|
||||
answer_id: e.target.id ? e.target.id : questions[indexQuestion].id
|
||||
}])
|
||||
answer_id: e.target.id ? e.target.id : questions[indexQuestion].id,
|
||||
},
|
||||
]);
|
||||
};
|
||||
|
||||
// const handleFieldsForm = (e) => {
|
||||
@ -25,5 +28,5 @@ export const useHandlerFieldTest = ({ questions, indexQuestion }) => {
|
||||
const handleChange = (e) => {
|
||||
handleChangeCheckbox(e);
|
||||
};
|
||||
return { handleChange, userResponses};
|
||||
return { handleChange, userResponses };
|
||||
};
|
||||
|
Reference in New Issue
Block a user