react-cursor-detection
v1.0.7
Published
A react component that detects the coordinates of the mouse relative to the component.
Maintainers
Readme
React cursor detection
A react component that detects the coordinates of the mouse relative to the component. An example can be found here.
Install
npm i react-cursor-detectionUsage
TypeScript
// App.tsx
import React from "react";
import ReactCursorDetection from "react-cursor-detection";
import ExampleUsage from "ExampleUsage";
export default function App() {
return <ReactCursorDetection>{(props) => <ExampleUsage {...props} />}</ReactCursorDetection>;
}// ExampleUsage.tsx
import React from "react";
import { ICursorDetectionPassThroughProps } from "react-cursor-detection";
interface IProps extends ICursorDetectionPassThroughProps {}
export default function ExampleUsage(props: IProps) {
const { isActive, position } = props;
const { x, y } = position;
return (
<div>
<p>isActive: {isActive ? "true" : "false"}</p>
<p>
x: {x}, y: {y}
</p>
</div>
);
}Development
Setup
Module
Install dependencies:
npm installThis should install dependencies for both the module and the example project (currently only works in linux). If the example project dependencies fail, then please follow the example cra dependency installation instructions.
To run in watch mode:
npm startTo build:
npm run buildExample create-react-app project
First, cd into the example directory:
cd exampleInstall dependencies:
npm installTo run development server:
npm startTo build:
npm run buildContributing
Please read CONTRIBUTING.md.
Credit
This project is based on this solution, but has now diverted significantly.
