Skip to content

Commit cc266a5

Browse files
committed
update docs to be more accurate
1 parent 9966243 commit cc266a5

File tree

1 file changed

+36
-8
lines changed

1 file changed

+36
-8
lines changed

README.md

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ npm install react-use-hoverintent
3333

3434
## Options
3535

36-
`ref`: the react element ref which you want hoverintent to be applied, required.
36+
`ref`: the react element ref which you want hoverintent to be applied.
3737

3838
`timeout` : A simple delay, in milliseconds, before the `onMouseOut` callback is fired. If the user mouses back over the element before the timeout has expired the `onMouseOut` callback will not be called (nor will the `onMouseOver` callback be called). This is primarily to protect against sloppy/human mousing trajectories that temporarily (and unintentionally) take the user off of the target element... giving them time to return.
3939

@@ -56,8 +56,8 @@ import React from "react";
5656
import { useHoverIntent } from "react-use-hoverintent";
5757

5858
export const MyFunctionalComponent = (props) => {
59-
const [isHovering, ref] = useHoverIntent();
60-
return <div ref={ref} className={`${isHovering ? "hover" : ""}`}></div>;
59+
const [isHovering, intentRef, setIsHovering] = useHoverIntent();
60+
return <div ref={intentRef} className={`${isHovering ? "hover" : ""}`}></div>;
6161
};
6262
```
6363

@@ -68,12 +68,12 @@ import React from "react";
6868
import { useHoverIntent } from "react-use-hoverintent";
6969

7070
export const MyFunctionalComponent = (props) => {
71-
const [isHovering, ref] = useHoverIntent({
71+
const [isHovering, intentRef, setIsHovering] = useHoverIntent({
7272
timeout: 100,
7373
sensitivity: 10,
7474
interval: 200,
7575
});
76-
return <div ref={ref} className={`${isHovering ? "hover" : ""}`}></div>;
76+
return <div ref={intentRef} className={`${isHovering ? "hover" : ""}`} />;
7777
};
7878
```
7979

@@ -84,8 +84,8 @@ import React from "react";
8484
import { useHoverIntent } from "react-use-hoverintent";
8585

8686
export const MyFunctionalComponent = React.forwardRef((props, ref) => {
87-
const [isHovering, intentRef] = useHoverIntent({ ref });
88-
return <div ref={intentRef} className={`${isHovering ? "hover" : ""}`}></div>;
87+
const [isHovering, intentRef, setIsHovering] = useHoverIntent({ ref });
88+
return <div ref={intentRef} className={`${isHovering ? "hover" : ""}`} />;
8989
});
9090
```
9191

@@ -98,7 +98,7 @@ import React from "react";
9898
import { useHoverIntent } from "react-use-hoverintent";
9999

100100
export const MyFunctionalComponent = (props) => {
101-
const [isHovering, intentRef] = useHoverIntent();
101+
const [isHovering, intentRef, setIsHovering] = useHoverIntent();
102102
return (
103103
<Card
104104
innerRef={intentRef}
@@ -108,6 +108,34 @@ export const MyFunctionalComponent = (props) => {
108108
};
109109
```
110110

111+
After v1.2.9
112+
113+
With custom hover state control
114+
115+
```javascript
116+
import React, { useCallback } from "react";
117+
import { useHoverIntent } from "react-use-hoverintent";
118+
119+
export const MyFunctionalComponent = (props) => {
120+
const [isHovering, intentRef, setIsHovering] = useHoverIntent();
121+
122+
const mouseOverHandler = useCallback(() => {
123+
() => setIsHovering(true);
124+
}, [setIsHovering]);
125+
126+
const mouseOutHandler = useCallback(() => {
127+
() => setIsHovering(false);
128+
}, [setIsHovering]);
129+
130+
return (
131+
<>
132+
<div ref={intentRef} className={`${isHovering ? "hover" : ""}`} />
133+
<textarea onMouseOver={mouseOverHandler} onMouseOut={mouseOutHandler} />
134+
</>
135+
);
136+
};
137+
```
138+
111139
## License
112140

113141
MIT

0 commit comments

Comments
 (0)