🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

@react-hook/mouse-position

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-hook/mouse-position - npm Package Compare versions

Comparing version

to
3.2.2

4

package.json
{
"name": "@react-hook/mouse-position",
"version": "3.2.1",
"version": "3.2.2",
"homepage": "https://github.com/jaredLunde/react-hook/tree/master/packages/mouse-position#readme",

@@ -82,3 +82,3 @@ "repository": "github:jaredLunde/react-hook",

"dependencies": {
"@react-hook/throttle": "^2.1.0"
"@react-hook/throttle": "^2.1.2"
},

@@ -85,0 +85,0 @@ "peerDependencies": {

@@ -26,5 +26,7 @@ <hr>

A React hook for tracking the position of the mouse as it moves around an element. This
hook also provides an interop between touch and desktop devices and will treat
`ontouch` events the same as `onmouse` ones.
A React hook for tracking the position, hover, and "down" state of the mouse as it interacts
with an element. This hook provides interoperability between touch and desktop devices and will treat
`ontouch` events the same as `onmouse` ones. Additionally, this hook is throttled to `30fps` by default
using a [useThrottle() hook](https://github.com/jaredLunde/react-hook/tree/master/packages/throttle),
though the precise frame rate is configurable.

@@ -44,2 +46,4 @@ ## Quick Start

return (
// You must provide the ref to the element you're tracking the
// mouse position of
<div ref={ref}>

@@ -57,20 +61,23 @@ Hover me and see where I am relative to the element:

### `useMousePosition(enterDelay?: number, leaveDelay?: number, fps?: number)`
### useMousePosition(enterDelay?, leaveDelay?, fps?)
A hook for tracking the mouse position in an element with interoperability between touch
devices and mouse devices.
#### Arguments
| Argument | Type | Default | Description |
| ---------- | -------- | ------- | ----------------------------------------------------------------------------------------------------- |
| enterDelay | `number` | `0` | The amount of time in `ms` to wait after an initial action before setting `mousemove` events to state |
| leaveDelay | `number` | `0` | The amount of time in `ms` to wait after a final action before setting `mouseleave` events to state |
| fps | `number` | `30` | The rate in frames-per-second that the state should update |
| Argument | Type | Default | Description |
| ---------- | -------- | ------- | ------------------------------------------------------------------------------------------------------ |
| enterDelay | `number` | `0` | The time in `ms` to wait after an initial action before setting the latest `mousemove` events to state |
| leaveDelay | `number` | `0` | The time in `ms` to wait after a final action before setting the latest `mouseleave` events to state |
| fps | `number` | `30` | The rate in frames-per-second that the mouse position should update |
#### Returns `[state: MousePosition, ref: (element: HTMLElement | null) => void]`
#### Returns `[state: MousePosition, ref: React.Dispatch<React.SetStateAction<HTMLElement | null>>]`
| Variable | Description |
| -------- | ----------------------------------------------------------------------------------------- |
| `state` | The mouse position data for the ref'd element |
| `ref` | The callback ref you must provide to the element you want to track mouse data position of |
| Variable | Type | Description |
| -------- | ---------------------------------------------------------- | -------------------------------------------------------------------------------- |
| `state` | [MousePosition](#mouseposition) | The mouse position data for the ref'd element |
| `ref` | `React.Dispatch<React.SetStateAction<HTMLElement | null>>` | The ref you have to provide to the element you're tracking the mouse position of |
#### state: MousePosition
#### MousePosition

@@ -77,0 +84,0 @@ | Key | Type | Default | Description |

@@ -17,7 +17,7 @@ import React from 'react'

}
export declare const useMousePosition: (
export declare const useMousePosition: <T extends HTMLElement = HTMLElement>(
enterDelay?: number,
leaveDelay?: number,
fps?: number
) => [MousePosition, React.Dispatch<React.SetStateAction<HTMLElement | null>>]
) => [MousePosition, React.Dispatch<React.SetStateAction<T | null>>]
export default useMousePosition