diff --git a/src/index.ts b/src/index.ts index 50ec5018..12881f2a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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' diff --git a/src/use-page-leave/demo.tsx b/src/use-document-leave/demo.tsx similarity index 100% rename from src/use-page-leave/demo.tsx rename to src/use-document-leave/demo.tsx diff --git a/src/use-page-leave/index.mdx b/src/use-document-leave/index.mdx similarity index 76% rename from src/use-page-leave/index.mdx rename to src/use-document-leave/index.mdx index 2942605e..e9257f2d 100644 --- a/src/use-page-leave/index.mdx +++ b/src/use-document-leave/index.mdx @@ -1,10 +1,10 @@ -# usePageLeave +# useDocumentLeave import { HooksType } from '@/components' -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 @@ -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. diff --git a/src/use-page-leave/index.ts b/src/use-document-leave/index.ts similarity index 78% rename from src/use-page-leave/index.ts rename to src/use-document-leave/index.ts index 30f9756e..6919eab5 100644 --- a/src/use-page-leave/index.ts +++ b/src/use-document-leave/index.ts @@ -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) }