import React, { useEffect, useRef, useState } from 'react'; export const Questions = ({ children }) => { return (
{children}
); }; export const Q = ({ children }) => { const [isAnswerVisible, setIsAnswerVisible] = useState(false); const answerRef = useRef(null); const [answerHeight, setAnswerHeight] = useState(0); useEffect(() => { if (answerRef.current) { setAnswerHeight(isAnswerVisible ? answerRef.current.scrollHeight : 0); } }, [isAnswerVisible]); const questionText = children[0]; const answerComponent = React.Children.toArray(children)[1]; const arrowClass = isAnswerVisible ? 'collapsible-arrow expanded' : 'collapsible-arrow'; return (
setIsAnswerVisible(!isAnswerVisible)}>
{questionText}
{answerComponent}
); }; export const A = ({ children }) => { return (
{children}
); };