You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The component renders a paragraph element with some text to which is attacched a ref used for __useHover__ hook that returns if element is hovered or not. This value is rendered into another paragraph element.
6
+
7
+
When mouse is hovered paragraph element, status changes to true.
8
+
*/
9
+
exportconstUseHover=()=>{
10
+
constpRef=useRef<HTMLParagraphElement>(null);
11
+
consthover=useHover(pRef);
12
+
13
+
return(
14
+
<div>
15
+
<p>Is hover: {hover ? "hover" : "not hover"}</p>
16
+
<pref={pRef}>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Id delectus deserunt atque! Est id voluptatem sint accusamus non doloribus totam nobis nostrum provident facilis eos eum, placeat consequatur minus quidem.</p>
Hook that determines whether the item is hovered or not and handles state hovers.
3
+
4
+
## Usage
5
+
6
+
```tsx
7
+
exportconst UseHover = () => {
8
+
const pRef =useRef<HTMLParagraphElement>(null);
9
+
const hover =useHover(pRef);
10
+
11
+
return (
12
+
<div>
13
+
<p>Is hover: {hover?"hover":"not hover"}</p>
14
+
<pref={pRef}>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Id delectus deserunt atque! Est id voluptatem sint accusamus non doloribus totam nobis nostrum provident facilis eos eum, placeat consequatur minus quidem.</p>
15
+
</div>
16
+
);
17
+
}
18
+
```
19
+
20
+
> The component renders a paragraph element with some text to which is attacched a ref used for __useHover__ hook that returns if element is hovered or not. This value is rendered into another paragraph element.
21
+
>
22
+
> When mouse is hovered paragraph element, status changes to true.
__onEnter__ function to be executed on starting hover, __onLeave__ function to be executed on hover finished, __onChange__ function to be executed when hover state changes, __return value__ boolean to return hover state value or not.
37
+
>
38
+
39
+
> ### Returns
40
+
>
41
+
> __result__: if __returnValue__ option is true or not specified, hook return state hover value, otherwise returns nothing.
* **`useHover`**: Hook that determines whether the item is hovered or not and handles state hovers.
6
+
* @param {RefObject<HTMLElement> | HTMLElement} target - DOM element or ref
7
+
* @param {{ onEnter?: (evt: Event) => void, onChange?: (isHover: boolean) => void, onLeave?: (evt: Event) => void, returnValue?: boolean }} [opts] - __onEnter__ function to be executed on starting hover, __onLeave__ function to be executed on hover finished, __onChange__ function to be executed when hover state changes, __return value__ boolean to return hover state value or not.
8
+
* @returns {boolean|void} result - if __returnValue__ option is true or not specified, hook return state hover value, otherwise returns nothing.
0 commit comments