
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
mouse-follow
Advanced tools
A React hook that enables elements to follow or move away from the mouse cursor, enhancing user interaction with dynamic cursor effects.

Install the package using npm:
npm install mouse-follow
Or with yarn:
yarn add mouse-follow
First, import the useMouseFollow hook into your React component:
import useMouseFollow from 'mouse-follow';
Then, apply the hook to your component:
import React from 'react';
import { useRef } from 'react'
import useMouseFollow from 'mouse-follow';
const FollowExample = () => {
const ref = useRef<HTMLDivElement>(null)
useMouseFollow(ref, {
boundaryX?: number, // Boundary width (default: element width) ex. 200
boundaryY?: number, // Boundary height (default: element height) ex. 300
duration?: number, // Time (in ms) for the element to return to its original position (default: 1000ms) 1500
follow?: boolean, // Whether the element follows the mouse or moves away (default: true)
return (
<div ref={ref}>
{/* Your content */}
</div>
);
};
export default YourComponent;
The useMouseFollow hook accepts an optional configuration object with the following properties:
| Property | Type | Description | Default |
|---|---|---|---|
follow | boolean | If true, the element follows the cursor; if false, the element moves away from the cursor. | true |
duration | number | Determines the time (in milliseconds) it takes for the element to return to its original position. A lower value results in faster movement. | 1000 |
boundaryX | number | Boundary width for the element's movement. If not provided, defaults to the element's width. | undefined |
boundaryY | number | Boundary height for the element's movement. If not provided, defaults to the element's height. | undefined |
Here's a simple example demonstrating how to use mouse-follow:
import React from 'react';
import { useRef } from 'react'
import useMouseFollow from 'mouse-follow';
const FollowExample = () => {
const divRef = useRef<HTMLDivElement>(null)
useMouseFollow(divRef, {
boundaryX: 400,
boundaryY: 400,
duration: 2000,
follow: true,
})
return (
<div
ref={divRef}
style={{
width: '50px',
height: '50px',
backgroundColor: 'blue',
borderRadius: '50%',
position: 'absolute',
}}
/>
);
};
export default FollowExample;
In this example, a blue circle will smoothly follow the mouse cursor around the screen. 🖱️💙
Contributions are welcome! If you have suggestions for improvements or encounter any issues, please open an issue or submit a pull request on the GitHub repository.
Steps to Contribute:
This project is licensed under the MIT License. See the LICENSE file for details.
Made with ❤️ by Ahmed Elkhdrawy.
FAQs
A React hook to make elements follow or move away from the mouse cursor.
We found that mouse-follow demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.