You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
boundary/website/lib/hooks/use-hover.js

30 lines
713 B

import { useRef, useState, useEffect } from 'react'
function useHover() {
const [value, setValue] = useState(false)
const ref = useRef(null)
const handleMouseOver = () => setValue(true)
const handleMouseOut = () => setValue(false)
useEffect(
() => {
const node = ref.current
if (node) {
node.addEventListener('mouseover', handleMouseOver)
node.addEventListener('mouseout', handleMouseOut)
return () => {
node.removeEventListener('mouseover', handleMouseOver)
node.removeEventListener('mouseout', handleMouseOut)
}
}
},
[ref.current] // Recall only if ref changes
)
return [ref, value]
}
export default useHover