MCPcopy Index your code
hub / github.com/TanStack/router / useIntersectionObserver

Function useIntersectionObserver

packages/solid-router/src/utils.ts:48–76  ·  view source on GitHub ↗
(
  ref: Solid.Accessor<T | null>,
  callback: (entry: IntersectionObserverEntry | undefined) => void,
  intersectionObserverOptions: IntersectionObserverInit = {},
  options: { disabled?: boolean } = {},
)

Source from the content-addressed store, hash-verified

46 * ```
47 */
48export function useIntersectionObserver<T extends Element>(
49 ref: Solid.Accessor<T | null>,
50 callback: (entry: IntersectionObserverEntry | undefined) => void,
51 intersectionObserverOptions: IntersectionObserverInit = {},
52 options: { disabled?: boolean } = {},
53): Solid.Accessor<IntersectionObserver | null> {
54 const isIntersectionObserverAvailable =
55 typeof IntersectionObserver === 'function'
56 let observerRef: IntersectionObserver | null = null
57
58 Solid.createEffect(() => {
59 const r = ref()
60 if (!r || !isIntersectionObserverAvailable || options.disabled) {
61 return
62 }
63
64 observerRef = new IntersectionObserver(([entry]) => {
65 callback(entry)
66 }, intersectionObserverOptions)
67
68 observerRef.observe(r)
69
70 Solid.onCleanup(() => {
71 observerRef?.disconnect()
72 })
73 })
74
75 return () => observerRef
76}

Callers 1

useLinkPropsFunction · 0.90

Calls 2

observeMethod · 0.45
disconnectMethod · 0.45

Tested by

no test coverage detected