
Product
Introducing Tier 1 Reachability: Precision CVE Triage for Enterprise Teams
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
@yhattav/react-component-cursor
Advanced tools
A lightweight, TypeScript-first React library for creating beautiful custom cursors with SSR support, smooth animations, and zero dependencies. Perfect for interactive websites, games, and creative applications.
A flexible and customizable React component for creating smooth, interactive custom cursors and enhancements.
npm install @yhattav/react-component-cursor
or
yarn add @yhattav/react-component-cursor
Note: If you wish to, You'll need to hide the native cursor with CSS (like cursor: none
in the example above). See our styling guide for different approaches.
📖 New to the library? Check out our comprehensive Getting Started Guide for step-by-step tutorials and examples.
import { CustomCursor } from '@yhattav/react-component-cursor';
function App() {
return (
<>
{/* Hide native cursor globally */}
<style>{`body { cursor: none !important; }`}</style>
<CustomCursor>
<div
style={{
width: '20px',
height: '20px',
backgroundColor: '#3b82f6',
borderRadius: '50%',
}}
/>
</CustomCursor>
{/* Your app content */}
</>
);
}
<CustomCursor>
ComponentThe main component for creating custom cursors.
Prop | Type | Default | Description |
---|---|---|---|
children | ReactNode | - | The React component/element to use as cursor content |
enabled | boolean | true | Whether the cursor is enabled and visible |
smoothness | number | 1 | Movement smoothing factor (1=instant, higher=smoother) |
containerRef | RefObject<HTMLElement> | - | Limit cursor to specific container element |
offset | CursorOffset | { x: 0, y: 0 } | Pixel offset from mouse position |
centered | boolean | true | Auto-center cursor content on mouse position |
throttleMs | number | 0 | Throttle mouse events in milliseconds |
className | string | '' | Additional CSS classes for cursor container |
style | CSSProperties | {} | Additional inline styles for cursor container |
zIndex | number | 9999 | CSS z-index for cursor container |
onMove | CursorMoveHandler | - | Callback fired on cursor movement |
onVisibilityChange | CursorVisibilityHandler | - | Callback fired when cursor visibility changes |
id | string | auto-generated | Unique identifier for cursor instance |
showDevIndicator | boolean | true | [Dev Only] Show debug ring in development |
data-testid | string | - | Test ID for automated testing |
role | string | - | ARIA role for accessibility |
aria-label | string | - | ARIA label for accessibility |
The library is written in TypeScript and includes built-in type definitions.
import type {
CustomCursorProps,
CursorPosition,
CursorOffset,
CursorMoveHandler,
CursorVisibilityHandler,
CursorVisibilityReason,
} from '@yhattav/react-component-cursor';
📖 Complete TypeScript Reference →
All prop types, interfaces, and future-ready types with usage examples.
Optional utility functions for advanced SSR scenarios:
import { isSSR, isBrowser, browserOnly, safeDocument, safeWindow } from '@yhattav/react-component-cursor';
Optimized for performance with advanced control for complex use cases.
📖 Complete Performance Guide →
Optimization strategies, settings matrix, and advanced techniques.
Works out of the box with Next.js, Gatsby, Remix, and other SSR frameworks.
// Zero configuration needed - SSR handled automatically
import { CustomCursor } from '@yhattav/react-component-cursor';
<CustomCursor>
<div className="cursor">✨</div>
</CustomCursor>
Live Demo: Interactive Examples & Showcase →
Local Examples (clone and run):
# Vite React example with multiple cursor demos
cd example && npm install && npm run dev
# Next.js example with SSR and advanced patterns
cd example-nextjs && npm install && npm run dev
function ContainerExample() {
const containerRef = useRef<HTMLDivElement>(null);
return (
<div
ref={containerRef}
style={{
position: 'relative',
cursor: 'none', // Hide native cursor in this container
}}
>
<CustomCursor containerRef={containerRef} smoothness={2}>
<div
style={{
width: '40px',
height: '40px',
border: '2px solid #ef4444',
borderRadius: '50%',
}}
/>
</CustomCursor>
{/* Container content */}
</div>
);
}
function InteractiveCursor() {
const [isHovered, setIsHovered] = useState(false);
return (
<>
<style>{`body { cursor: none; }`}</style>
<div>
<CustomCursor>
<div
style={{
width: isHovered ? '60px' : '20px',
height: isHovered ? '60px' : '20px',
backgroundColor: '#3b82f6',
borderRadius: '50%',
transition: 'all 0.2s ease',
}}
/>
</CustomCursor>
<button
onMouseEnter={() => setIsHovered(true)}
onMouseLeave={() => setIsHovered(false)}
>
Hover me!
</button>
</div>
</>
);
}
function VisibilityAwareCursor() {
const handleVisibilityChange = (isVisible: boolean, reason: string) => {
console.log('Cursor visibility:', isVisible, 'reason:', reason);
// Reason can be: 'container', 'disabled', or other values in future versions
};
return (
<CustomCursor onVisibilityChange={handleVisibilityChange}>
<div
style={{
width: '20px',
height: '20px',
backgroundColor: '#3b82f6',
borderRadius: '50%',
}}
/>
</CustomCursor>
);
}
We welcome contributions! See our guides:
MIT © Yonatan Hattav
FAQs
A lightweight, TypeScript-first React library for creating beautiful custom cursors with SSR support, smooth animations, and zero dependencies. Perfect for interactive websites, games, and creative applications.
The npm package @yhattav/react-component-cursor receives a total of 75 weekly downloads. As such, @yhattav/react-component-cursor popularity was classified as not popular.
We found that @yhattav/react-component-cursor demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.