@a-type/ui 6.1.27 → 6.1.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function useOnVisible(onVisible?: () => void): import("react").RefObject<
|
|
1
|
+
export declare function useOnVisible(onVisible?: () => void): import("react").RefObject<any>;
|
|
@@ -4,6 +4,11 @@ export function useOnVisible(onVisible) {
|
|
|
4
4
|
const innerRef = useRef(null);
|
|
5
5
|
const stableOnVisible = useStableCallback(onVisible);
|
|
6
6
|
useEffect(() => {
|
|
7
|
+
const current = innerRef.current;
|
|
8
|
+
if (!current ||
|
|
9
|
+
!(current instanceof HTMLElement || current instanceof SVGElement)) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
7
12
|
const observer = new IntersectionObserver((entries) => {
|
|
8
13
|
if (entries[0].isIntersecting) {
|
|
9
14
|
stableOnVisible();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOnVisible.js","sourceRoot":"","sources":["../../src/hooks/useOnVisible.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,MAAM,UAAU,YAAY,CAAC,SAAsB;IAClD,MAAM,QAAQ,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"useOnVisible.js","sourceRoot":"","sources":["../../src/hooks/useOnVisible.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,MAAM,UAAU,YAAY,CAAC,SAAsB;IAClD,MAAM,QAAQ,GAAG,MAAM,CAAM,IAAI,CAAC,CAAC;IAEnC,MAAM,eAAe,GAAG,iBAAiB,CAAC,SAAS,CAAC,CAAC;IACrD,SAAS,CAAC,GAAG,EAAE;QACd,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC;QACjC,IACC,CAAC,OAAO;YACR,CAAC,CAAC,OAAO,YAAY,WAAW,IAAI,OAAO,YAAY,UAAU,CAAC,EACjE,CAAC;YACF,OAAO;QACR,CAAC;QAED,MAAM,QAAQ,GAAG,IAAI,oBAAoB,CAAC,CAAC,OAAO,EAAE,EAAE;YACrD,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,cAAc,EAAE,CAAC;gBAC/B,eAAe,EAAE,CAAC;YACnB,CAAC;QACF,CAAC,CAAC,CAAC;QACH,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAQ,CAAC,CAAC;QACpC,OAAO,GAAG,EAAE;YACX,QAAQ,CAAC,UAAU,EAAE,CAAC;QACvB,CAAC,CAAC;IACH,CAAC,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC;IAEtB,OAAO,QAAQ,CAAC;AACjB,CAAC"}
|
package/package.json
CHANGED
|
@@ -2,10 +2,18 @@ import { useEffect, useRef } from 'react';
|
|
|
2
2
|
import { useStableCallback } from './useStableCallback.js';
|
|
3
3
|
|
|
4
4
|
export function useOnVisible(onVisible?: () => void) {
|
|
5
|
-
const innerRef = useRef<
|
|
5
|
+
const innerRef = useRef<any>(null);
|
|
6
6
|
|
|
7
7
|
const stableOnVisible = useStableCallback(onVisible);
|
|
8
8
|
useEffect(() => {
|
|
9
|
+
const current = innerRef.current;
|
|
10
|
+
if (
|
|
11
|
+
!current ||
|
|
12
|
+
!(current instanceof HTMLElement || current instanceof SVGElement)
|
|
13
|
+
) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
9
17
|
const observer = new IntersectionObserver((entries) => {
|
|
10
18
|
if (entries[0].isIntersecting) {
|
|
11
19
|
stableOnVisible();
|