Files
5chan/src/components/ForwardRefLink.jsx
T

35 lines
777 B
React
Raw Normal View History

2023-06-22 14:59:30 +02:00
import React, { useEffect } from "react";
import { Link } from "react-router-dom";
const ForwardRefLink = React.forwardRef((props, ref) => {
const { children, setRefAndCid, onMouseOver, onMouseLeave, onClick, ...otherProps } = props;
2023-08-22 11:49:04 +02:00
const handleClick = (event) => {
if (otherProps.to === "#void") {
event.preventDefault();
}
if (onClick) {
onClick(event);
}
};
2023-06-22 14:59:30 +02:00
useEffect(() => {
if (ref.current && typeof setRefAndCid === 'function') {
setRefAndCid(ref.current);
}
}, [ref, setRefAndCid]);
return (
<Link
ref={ref}
{...otherProps}
onMouseOver={onMouseOver}
onMouseLeave={onMouseLeave}
2023-08-22 11:49:04 +02:00
onClick={handleClick}
2023-06-22 14:59:30 +02:00
>
{children}
</Link>
);
});
export default ForwardRefLink;