Skip to content

Commit

Permalink
chore: change name usePageLeave to useDocument
Browse files Browse the repository at this point in the history
  • Loading branch information
vikiboss committed Jun 17, 2024
1 parent 306fc27 commit 5daee32
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export * from './use-mutation-observer'
export * from './use-network'
export * from './use-now'
export * from './use-online'
export * from './use-page-leave'
export * from './use-document-leave'
export * from './use-pagination'
export * from './use-parallax'
export * from './use-parent-element'
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# usePageLeave
# useDocumentLeave

import { HooksType } from '@/components'

<HooksType category="Sensors" />

A React Hook that tracks whether the user is leaving the page.
A React Hook that tracks whether the user is leaving the document.

## Demo

Expand All @@ -30,9 +30,9 @@ import { Source } from '@/components'
## API

```tsx
const isPageLeave = usePageLeave()
const isDocumentLeave = useDocumentLeave()
```

### Returns

A `boolean` value that indicates whether the user is leaving the page or not.
A `boolean` value that indicates whether the user is leaving the document or not.
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { useEventListener } from '../use-event-listener'
import { useSafeState } from '../use-safe-state'

export interface UsePageLeaveEvent {
export interface UseDocumentLeaveEvent {
relatedTarget?: EventTarget | null
toElement?: EventTarget | null
}

export function usePageLeave() {
export function useDocumentLeave() {
const [isLeft, setIsLeft] = useSafeState(false)

function handler(event: MouseEvent) {
const evt = (event || window.event) as UsePageLeaveEvent
const evt = (event || window.event) as UseDocumentLeaveEvent
const from = evt.relatedTarget || evt.toElement
setIsLeft(!from)
}
Expand Down

0 comments on commit 5daee32

Please sign in to comment.