Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exposed setIsHovering state setter #37

Merged
merged 1 commit into from
Oct 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions dist/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</a>
</p>

react-use-hoverintent is a react hook which allows you to use classic hoverintent behaviour in modern, react way.
react-use-hoverintent is a react hook which allows you to use classic hoverintent behavior in modern, react way.

"hoverIntent is a plug-in that attempts to determine the user's intent... like a crystal ball, only with mouse movement! It is similar to jQuery's hover method. However, instead of calling the handlerIn function immediately, hoverIntent waits until the user's mouse slows down enough before making the call."

Expand Down Expand Up @@ -52,40 +52,40 @@ Default `interval: 100`
Basic usage

```javascript
import React from 'react';
import { useHoverIntent } from 'react-use-hoverintent';
import React from "react";
import { useHoverIntent } from "react-use-hoverintent";

export const MyFunctionalComponent = (props) => {
const [isHovering, ref] = useHoverIntent();
return <div ref={ref} className={`${isHovering ? 'hover' : ''}`}></div>;
return <div ref={ref} className={`${isHovering ? "hover" : ""}`}></div>;
};
```

With options

```javascript
import React from 'react';
import { useHoverIntent } from 'react-use-hoverintent';
import React from "react";
import { useHoverIntent } from "react-use-hoverintent";

export const MyFunctionalComponent = (props) => {
const [isHovering, ref] = useHoverIntent({
timeout: 100,
sensitivity: 10,
interval: 200,
});
return <div ref={ref} className={`${isHovering ? 'hover' : ''}`}></div>;
return <div ref={ref} className={`${isHovering ? "hover" : ""}`}></div>;
};
```

With ForwardRef

```js
import React from 'react';
import { useHoverIntent } from 'react-use-hoverintent';
import React from "react";
import { useHoverIntent } from "react-use-hoverintent";

export const MyFunctionalComponent = React.forwardRef((props, ref) => {
const [isHovering, intentRef] = useHoverIntent({ ref });
return <div ref={intentRef} className={`${isHovering ? 'hover' : ''}`}></div>;
return <div ref={intentRef} className={`${isHovering ? "hover" : ""}`}></div>;
});
```

Expand All @@ -94,15 +94,15 @@ With Custom UI lib
Check if they have `innerRef` prop or forwarded ref

```javascript
import React from 'react';
import { useHoverIntent } from 'react-use-hoverintent';
import React from "react";
import { useHoverIntent } from "react-use-hoverintent";

export const MyFunctionalComponent = (props) => {
const [isHovering, intentRef] = useHoverIntent();
return (
<Card
innerRef={intentRef}
className={`${isHovering ? 'hover' : ''}`}
className={`${isHovering ? "hover" : ""}`}
></Card>
);
};
Expand Down
4 changes: 2 additions & 2 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/// <reference types="react" />
import { Dispatch, SetStateAction } from "react";
interface optionType {
ref?: React.Ref<HTMLElement | null>;
sensitivity?: number;
interval?: number;
timeout?: number;
}
export declare function useHoverIntent<T = HTMLElement>(options?: optionType): [boolean, React.RefObject<HTMLElement & T>];
export declare const useHoverIntent: <T>(options?: optionType | undefined) => [boolean, Dispatch<SetStateAction<boolean>>, import("react").RefObject<HTMLElement & T>];
export {};
Loading