import React, { useRef, useState, useEffect } from 'react'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faCopy, faCheck } from '@fortawesome/free-solid-svg-icons'; const CodeBlock = ({ children }) => { const textareaRef = useRef(null); const [codeString, setCodeString] = useState(''); const [copied, setCopied] = useState(false); // New state variable useEffect(() => { if (textareaRef.current) { setCodeString(textareaRef.current.textContent || ''); } }, [children]); const handleCopyClick = () => { if (codeString) { navigator.clipboard.writeText(codeString).then(() => { setCopied(true); // Set copied state to true setTimeout(() => setCopied(false), 3000); // Reset after 3 seconds //alert('Code copied to clipboard!'); }, () => { alert('Failed to copy code!'); }); } }; return (
        
          {children}
        
      
); }; export default CodeBlock;