Latest Threat ResearchGlassWorm Loader Hits Open VSX via Developer Account Compromise.Details
Socket
Book a DemoInstallSign in
Socket

react-hover-slop

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-hover-slop

Expand the area of the mouseOver, mouseLeave and mouseEnter events for React components. Usefull for if you want to prefetch earlier than regular hover

Source
npmnpm
Version
1.0.5
Version published
Weekly downloads
5
-58.33%
Maintainers
1
Weekly downloads
 
Created
Source

React Hover Slop

A React hook that expands the area of the mouseOver, mouseLeave and mouseEnter events for React components. Usefull for if you want to prefetch earlier than regular hover

Live Demo

Installation

npm install react-hover-slop
# or
yarn add react-hover-slop
# or
pnpm add react-hover-slop

Why React Hover Slop?

  • Predictive Intent: Detects user intent before they actually hover over an element
  • Early Data Fetching: Pre-fetch data when users approach elements, reducing perceived loading times

Usage

import { useRef } from 'react';
import useHoverslop from 'react-hover-slop';

function MyComponent() {
  const buttonRef = useRef(null);
  
  const { isHovered } = useHoverslop(
    buttonRef,
    { top: 20, right: 20, bottom: 20, left: 20 }, // Extend hover hitbox 20px in all directions
    {
      onMouseEnter: () => console.log('Mouse entered extended area'),
      onMouseLeave: () => console.log('Mouse left extended area'),
    }
  );
  
  return (
    <button 
      ref={buttonRef}
      style={{ 
        backgroundColor: isHovered ? 'blue' : 'gray',
        transition: 'background-color 0.3s'
      }}
    >
      Hover Me
    </button>
  );
}

API

useHoverslop(elementRef, hoverslopBox, mouseEvents, debugMode?)

Parameters

  • elementRef: React ref to the target element
  • hoverslopBox: Either a number (applies to all sides) or an object with optional top, right, bottom, and left properties
  • mouseEvents: Object containing optional callback functions:
    • onMouseEnter: Called when the cursor enters the extended area
    • onMouseOver: Called repeatedly while the cursor is in the extended area
    • onMouseLeave: Called when the cursor leaves the extended area
  • debugMode: Boolean to enable visual debugging of hover areas (optional)

Returns

  • isHovered: Boolean indicating whether the cursor is within the extended area

Visual Debugging

Adds a visual border around the element for debugging your slop boxes.

Adds a visual border around the element for debugging your slop boxes.

License

MIT

Keywords

hover-slop

FAQs

Package last updated on 02 May 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