-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
27758c4
commit b22559d
Showing
4 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { useState, useEffect } from "react"; | ||
|
||
/** | ||
* @typedef {Object} MousePosition | ||
* @property {number} x - X Coordinate of the mouse | ||
* @property {number} y - Y Coordinate of the mouse. | ||
*/ | ||
|
||
/** | ||
* | ||
* Custom hook which return an object with current coordinates of mouse pointer. | ||
* @return {MousePosition} Object containing the coordinates of the mouse pointer. | ||
*/ | ||
const useMousePosition = () => { | ||
const [coordinates, setCoordinates] = useState({}); | ||
|
||
useEffect(() => { | ||
//Event listener to track the mouse location. | ||
window.addEventListener("mousemove", (e) => { | ||
const mousePosition = { | ||
x: e.clientX, | ||
y: e.clientY, | ||
}; | ||
|
||
setCoordinates(mousePosition); | ||
}); | ||
}, []); | ||
|
||
return coordinates; | ||
}; | ||
|
||
export default useMousePosition; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters