import React, { useState, useRef, useEffect } from "react"; import { IQuestionData } from "../types"; import { getResultElementByType } from "../helpers/question.helper"; type AccordionProps = { question: IQuestionData; answers: any; }; export const Accordion = ({ question, answers }: AccordionProps) => { const [isOpened, setOpened] = useState(false); const [height, setHeight] = useState("0px"); const contentElement = useRef(null); const handleOpening = () => { setOpened(!isOpened); setHeight(!isOpened ? `${contentElement.current?.scrollHeight}px` : "0px"); }; return (

{question.title}

{isOpened ? "△" : "▽"}
{answers && getResultElementByType(question, answers)}
); }; export default Accordion;