React hook for mouse position on window
Note: This is using the new React Hooks API Proposal which is subject to change until React 16.7 final.
You'll need to install
react
,react-dom
, etc at^16.7.0-alpha.0
yarn add @rehooks/window-mouse-position
import useWindowMousePosition from "@rehooks/window-mouse-position";
function MyComponent() {
let { x, y } = useWindowMousePosition();
return (
<div style={{ width: "100%", height: "100%" }}>
<pre>{JSON.stringify({ x, y })}</pre>
</div>
);
}