import React, { useState, useRef, useEffect } from "react"; import { IQuestionData } from "../types"; import { getResultElementByType } from "../helpers/question.helper"; type AccordionProps = { question: IQuestionData; }; export const Accordion = ({ question }: 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 ? "△" : "▽"}
{question.answers && getResultElementByType(question)}
); }; export default Accordion;