npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@yhattav/react-component-cursor

v1.0.0

Published

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.

Downloads

374

Readme

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

| 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 |

📦 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