lbry-desktop/ui/effects/use-hover.js

24 lines
633 B
JavaScript
Raw Normal View History

import { useEffect, useState } from 'react';
export default function useHover(ref) {
const [isHovering, setIsHovering] = useState(false);
useEffect(() => {
function handleHover() {
setIsHovering(!isHovering);
}
const refElement = ref.current;
if (refElement) {
2019-07-17 22:49:06 +02:00
refElement.addEventListener('mouseenter', handleHover);
refElement.addEventListener('mouseleave', handleHover);
return () => {
2019-07-17 22:49:06 +02:00
refElement.removeEventListener('mouseenter', handleHover);
refElement.removeEventListener('mouseleave', handleHover);
};
}
}, [ref, isHovering]);
return isHovering;
}