import React from "react"
export const useMousePosition = () => {
const [mousePosition, setMousePosition] = React.useState({
x: 0,
y: 0,
})
React.useEffect(() => {
const updateMousePosition = (event) => {
setMousePosition({
x: event.clientX,
y: event.clientY,
})
}
window.addEventListener("mousemove", updateMousePosition)
return () => {
window.removeEventListener("mousemove", updateMousePosition)
}
}, [])
return mousePosition
}