Skip to content

doiali/use-hover-react

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-use-hover

a hook that returns a hover state and a ref, pass the ref to a component, then the hover state becomes true when the mouse is hovering that component

Installation

npm install @doiali/use-hover

Usage

import React from 'react';
import useHover from '@doiali/use-hover';

export default function SayHello() {
    const [isHovering,ref] = useHover();
    const style = {
        height:80,
        width:150,
        textAlign: "center",
        margin:'auto',
        border:`1px solid black`,
    }

    return (
        <div ref={ref} style={style}>
            hover me! <br/>
            {isHovering && "Hello!"}
        </div>
    )
}

About

a hook that returns a hover state and a ref, pass the ref to a component, then the hover state becomes true when the mouse is hovering that component

Resources

Stars

Watchers

Forks

Packages

No packages published