All Projects → andrewbranch → react-use-hover

andrewbranch / react-use-hover

Licence: MIT license
State hook to determine whether a React element is being hovered

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to react-use-hover

mithril-hooks
Use hooks in Mithril
Stars: ✭ 37 (-30.19%)
Mutual labels:  hooks-api-react
react-singleton-hook
Create singleton hook from regular react hook
Stars: ✭ 107 (+101.89%)
Mutual labels:  hooks-api-react
react-md-table-generator
Markdown Table Generator in React
Stars: ✭ 19 (-64.15%)
Mutual labels:  hooks-api-react
react-abac
Attribute Based Access Control for React
Stars: ✭ 54 (+1.89%)
Mutual labels:  hooks-api-react
curso-react-bootcamp
🦋 Repositório com o conteúdo das aulas do bootcamp de react
Stars: ✭ 14 (-73.58%)
Mutual labels:  hooks-api-react
on-outside-click-hook
A React custom hook to detect clicks which triggers outside the element and then fire an event.
Stars: ✭ 17 (-67.92%)
Mutual labels:  hooks-api-react
Websocket-React-Chatroom
A chatroom powered by React-Hooks and Websocket🚀
Stars: ✭ 76 (+43.4%)
Mutual labels:  hooks-api-react

react-use-hover Build Status NPM Version Minified size Greenkeeper badge

A React state hook to determine whether a React element is being hovered.

Installation

npm install react-use-hover

Usage

import useHover from 'react-use-hover';

function Tooltip() {
  const [isHovering, hoverProps] = useHover();
  return (
    <>
      <span {...hoverProps} aria-describedby="overlay">Hover me</span>
      <Overlay visible={isHovering} role="tooltip" id="overlay">
        I’m a lil popup or something!
      </Overlay>
    </>
  );
}

Options

useHover({
  mouseEnterDelayMS,
  mouseLeaveDelayMS
})
  • mouseEnterDelayMS: number = 200. The number of milliseconds to delay before setting the isHovering state to true. (Mousing back out during this delay period will cancel the state change.)
  • mouseLeaveDelayMS: number = 0. The number of milliseconds to delay before setting the isHovering state to false. (Mousing back in during this period will cancel the state change.)

Testing

# Run once, with coverage
npm run test

# Watch mode
npm run test -- --watch

# Do whatever you want
npx jest src # --any --jest --options

Contributing

PRs welcome! Please ensure you npm run build and commit before pushing (to run prettier) and maintain 100% test coverage.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].