import React, { useState } from "react"; import { CheckboxType, AnswersType, AnswerProps } from "../types"; interface Props extends AnswerProps { element: CheckboxType; answerQuestion: any | undefined; } export const ACheckboxForm = ({ element, answerQuestion }: Props) => { const [answer, setAnswer] = useState(""); const handleChange = (event: React.ChangeEvent) => { const { value } = event.currentTarget; if (answerQuestion.answer) { if (answerQuestion.answer.find((a: any) => a === value)) { const newList = answerQuestion.answer.filter((a: any) => a !== value); answerQuestion.answer = newList; if (answerQuestion.answer.length) { answerQuestion.requiredCheck = true; } else { answerQuestion.requiredCheck = false; } } else { answerQuestion.answer.push(value); answerQuestion.requiredCheck = true; } } else { answerQuestion.answer = []; answerQuestion.answer.push(value); answerQuestion.requiredCheck = true; } setAnswer(value); console.log(answerQuestion); }; return (
{element.content.choices.map((choice) => (
))}
); };