Skip to content

Commit

Permalink
refactor(use-is-visible): refactor types
Browse files Browse the repository at this point in the history
  • Loading branch information
andrepolischuk committed Nov 8, 2024
1 parent d68c672 commit fedbedc
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions packages/use-is-visible/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
/* eslint-disable import/no-unused-modules */
import {useEffect, useState} from 'react'

const DEFAULT_OPTIONS = {
threshold: 1,
once: false
}

/** Use is visible options */
export interface UseIsVisibleOptions extends IntersectionObserverInit {
/** Track intersection once */
once: boolean
}

/** Tracks the intersection of an element with its parent or document's viewport. */
export function useIsVisible(
element: Element,
options: IntersectionObserverInit & {once: boolean} = {
threshold: 1,
once: false
}
options: UseIsVisibleOptions = DEFAULT_OPTIONS
): boolean {
const [isVisible, setIsVisible] = useState(false)

Expand Down

0 comments on commit fedbedc

Please sign in to comment.