export function PopOver({title, link}){
const [content, setContent] = useState('');
useEffect(() => {
fetch(link)
.then(res => res.text())
.then(text => {
const parser = new DOMParser();
const htmlDocument = parser.parseFromString(text, 'text/html');
const specificContent = htmlDocument.querySelector('.markdown').innerHTML;
setContent(specificContent);
})
.catch(err => setContent(`<h3>${title}</h3>`));
}, []);
return (
<div className='popover'>
{parse(content)}
</div>
)
}
export default function InternalLink({children, link, content}) {
const [isHovered, setIsHovered] = useState(false);
const handleMouseOver = () =>{
setIsHovered(true);
}
const handleMouseOut = () =>{
setIsHovered(false);
}
return (
<div style={{display: 'inline'}} onMouseOver={handleMouseOver} onMouseOut={handleMouseOut}>
<a href={link}className='internal-link'>{children}</a>
{isHovered && <PopOver title={children} link={link}/>}
</div>
);
}