Socket
Book a DemoInstallSign in
Socket

@yhattav/react-component-cursor

Package Overview
Dependencies
Maintainers
1
Versions
88
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@yhattav/react-component-cursor

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.

latest
Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
76
162.07%
Maintainers
1
Weekly downloads
 
Created
Source

React Component Cursor

npm version npm downloads bundle size TypeScript MIT License Demo GitHub stars

A flexible and customizable React component for creating smooth, interactive custom cursors and enhancements.

Features

  • Use any React component
  • Smooth cursor movement with configurable smoothing
  • Global and Container-specific cursors
  • Supports Multiple instances
  • Lightweight (<10KB)
  • Zero dependencies (except React)

Installation

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.

Basic Usage

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 */}
    </>
  );
}

📋 Complete API Reference

<CustomCursor> Component

The main component for creating custom cursors.

Props

PropTypeDefaultDescription
childrenReactNode-The React component/element to use as cursor content
enabledbooleantrueWhether the cursor is enabled and visible
smoothnessnumber1Movement smoothing factor (1=instant, higher=smoother)
containerRefRefObject<HTMLElement>-Limit cursor to specific container element
offsetCursorOffset{ x: 0, y: 0 }Pixel offset from mouse position
centeredbooleantrueAuto-center cursor content on mouse position
throttleMsnumber0Throttle mouse events in milliseconds
classNamestring''Additional CSS classes for cursor container
styleCSSProperties{}Additional inline styles for cursor container
zIndexnumber9999CSS z-index for cursor container
onMoveCursorMoveHandler-Callback fired on cursor movement
onVisibilityChangeCursorVisibilityHandler-Callback fired when cursor visibility changes
idstringauto-generatedUnique identifier for cursor instance
showDevIndicatorbooleantrue[Dev Only] Show debug ring in development
data-testidstring-Test ID for automated testing
rolestring-ARIA role for accessibility
aria-labelstring-ARIA label for accessibility

📦 TypeScript Types

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.

🔧 SSR Utilities

Optional utility functions for advanced SSR scenarios:

import { isSSR, isBrowser, browserOnly, safeDocument, safeWindow } from '@yhattav/react-component-cursor';

📖 Complete SSR Guide →

⚡ Performance

Optimized for performance with advanced control for complex use cases.

📖 Complete Performance Guide →

Optimization strategies, settings matrix, and advanced techniques.

🌍 Server-Side Rendering (SSR)

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>

📖 Complete SSR Guide →

🎮 Examples & Demos

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

📚 Usage Guidelines

Framework Compatibility

  • Next.js - Full SSR support with zero configuration
  • Gatsby - Static generation compatible
  • Remix - Server-side rendering works out of the box
  • Vite/CRA - Client-side rendering with optimal performance
  • Astro - Partial hydration compatible

Advanced Usage

Container-Specific Cursor

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>
  );
}

Interactive Cursor

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>
    </>
  );
}

Visibility Change Handler

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>
  );
}

Contributing

We welcome contributions! See our guides:

License

MIT © Yonatan Hattav

Keywords

react

FAQs

Package last updated on 19 Jul 2025

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.