import React, {useEffect, useRef, useState} from "react"; import {Link} from "@heroui/react"; import {HashLinearIcon} from "@/components/icons"; export interface Props { id?: string; children?: React.ReactNode; } export const virtualAnchorEncode = (text?: string) => { if (!text) return undefined; return text.toLowerCase().replace(/ /g, "-"); }; export const VirtualAnchor: React.FC = ({children, id}) => { const ref = useRef(null); const [anchorId, setAnchorId] = useState(); useEffect(() => { if (!ref.current || !id) return; setAnchorId(virtualAnchorEncode(ref.current.textContent || undefined)); }, [ref.current, id]); return ( {children} ); };