import "./Object.scss"; import { useState, useEffect, useRef } from "react"; function Object(props) { const [isExpanded, setIsExpanded] = useState(false); const [needsExpansion, setNeedsExpansion] = useState(false); const contentRef = useRef(null); const handleCardClick = (e) => { // Don't redirect if user clicked on the expand button if (e.target.closest('.item__expand-btn')) { return; } if (props.cianUrl) { window.open(props.cianUrl, '_blank'); } }; useEffect(() => { const checkExpansion = () => { if (!props.desc || !props.address || !contentRef.current) { setNeedsExpansion(false); return; } const contentElement = contentRef.current; const contentHeight = contentElement.scrollHeight; const containerHeight = contentElement.clientHeight; const needsExp = contentHeight > containerHeight; setNeedsExpansion(needsExp); }; setTimeout(checkExpansion, 100); const handleResize = () => { setTimeout(checkExpansion, 100); }; window.addEventListener('resize', handleResize); return () => window.removeEventListener('resize', handleResize); }, [props.desc, props.address]); const toggleExpansion = () => { setIsExpanded(!isExpanded); }; return (
квартира

{props.price}

{props.desc}

{props.address}

{needsExpansion && (
)}
); } export { Object };