use-element-hover
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

Use Element Hover

A custom React hook for managing hover state. This hook provides an easy way to track whether an element is being hovered and applies event handlers for mouse over and mouse leave events.

Installation

You can install the package via npm:

npm install use-element-hover

Or using yarn:

yarn add use-element-hover

Usage

To use the use-element-hover hook, import it into your component and spread the returned event handlers onto the desired element.

Example

import React from 'react';
import { useHover } from 'use-element-hover';

const HoverInput = () => {
  const { isHovering, handlers } = useHover();

  return (
    <div>
      <input 
        type="text" 
        {...handlers} // Spread the handlers into the input
        placeholder="Hover over me!" 
      />
      {isHovering && <p>Input is being hovered!</p>}
    </div>
  );
};

export default HoverInput;

Author

Package Sidebar

Install

npm i use-element-hover

Weekly Downloads

4

Version

1.0.0

License

MIT

Unpacked Size

4.5 kB

Total Files

6

Last publish

Collaborators

  • behzadbakhshayesh